diff options
author | Luke Kanies <luke@madstop.com> | 2009-02-13 00:29:07 -0600 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-02-28 09:16:42 +1100 |
commit | fa6494b69ad1b01a9c587c86aa1731f4702f5509 (patch) | |
tree | 5a8aaa6c15aca51fdcb6fde067aa4d7cb73f30e2 | |
parent | 373d505c381696f880c305a9357a6e50342079b8 (diff) | |
download | puppet-fa6494b69ad1b01a9c587c86aa1731f4702f5509.tar.gz puppet-fa6494b69ad1b01a9c587c86aa1731f4702f5509.tar.xz puppet-fa6494b69ad1b01a9c587c86aa1731f4702f5509.zip |
Using the FileCollection where appropriate.
This commit just replaces the :file and :line accessors
with the use of the new FileCollection Lookup module.
This should mean that we've normalized all file names in
a given process, which *might* have drastic RAM improvements.
For initial simplicity, I've gone with a single global
collection of file names, but it's built so it's easy to use
individual file collections instead.
Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r-- | lib/puppet/file_collection.rb | 8 | ||||
-rw-r--r-- | lib/puppet/file_collection/lookup.rb | 4 | ||||
-rw-r--r-- | lib/puppet/parser/ast.rb | 7 | ||||
-rw-r--r-- | lib/puppet/parser/ast/leaf.rb | 2 | ||||
-rw-r--r-- | lib/puppet/parser/ast/resource_override.rb | 4 | ||||
-rw-r--r-- | lib/puppet/parser/resource.rb | 6 | ||||
-rw-r--r-- | lib/puppet/parser/resource/param.rb | 6 | ||||
-rw-r--r-- | lib/puppet/parser/resource/reference.rb | 2 | ||||
-rw-r--r-- | lib/puppet/type.rb | 4 | ||||
-rwxr-xr-x | spec/unit/file_collection.rb | 8 | ||||
-rwxr-xr-x | spec/unit/file_collection/lookup.rb | 7 | ||||
-rw-r--r-- | spec/unit/parser/ast.rb | 6 | ||||
-rwxr-xr-x | spec/unit/parser/resource.rb | 4 | ||||
-rwxr-xr-x | spec/unit/parser/resource/reference.rb | 4 |
14 files changed, 60 insertions, 12 deletions
diff --git a/lib/puppet/file_collection.rb b/lib/puppet/file_collection.rb index 451b496a1..69f59ffdf 100644 --- a/lib/puppet/file_collection.rb +++ b/lib/puppet/file_collection.rb @@ -1,6 +1,12 @@ # A simple way to turn file names into singletons, # so we don't have tons of copies of each file path around. class Puppet::FileCollection + require 'puppet/file_collection/lookup' + + def self.collection + @collection + end + def initialize @paths = [] end @@ -17,4 +23,6 @@ class Puppet::FileCollection def path(index) @paths[index] end + + @collection = self.new end diff --git a/lib/puppet/file_collection/lookup.rb b/lib/puppet/file_collection/lookup.rb index 8f69c6681..ddb0c8431 100644 --- a/lib/puppet/file_collection/lookup.rb +++ b/lib/puppet/file_collection/lookup.rb @@ -5,6 +5,10 @@ require 'puppet/file_collection' module Puppet::FileCollection::Lookup attr_accessor :line, :file_index + def file_collection + Puppet::FileCollection.collection + end + def file=(path) @file_index = file_collection.index(path) end diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb index 303d75bac..ab23dd1f8 100644 --- a/lib/puppet/parser/ast.rb +++ b/lib/puppet/parser/ast.rb @@ -2,6 +2,7 @@ require 'puppet' require 'puppet/util/autoload' +require 'puppet/file_collection/lookup' # The base class for all of the objects that make up the parse trees. # Handles things like file name, line #, and also does the initialization @@ -10,11 +11,13 @@ class Puppet::Parser::AST # Do this so I don't have to type the full path in all of the subclasses AST = Puppet::Parser::AST + include Puppet::FileCollection::Lookup + include Puppet::Util::Errors include Puppet::Util::MethodHelper include Puppet::Util::Docs - attr_accessor :line, :file, :parent, :scope + attr_accessor :parent, :scope # don't fetch lexer comment by default def use_docs @@ -82,8 +85,6 @@ class Puppet::Parser::AST # method for them. This is probably pretty inefficient and should # likely be changed at some point. def initialize(args) - @file = nil - @line = nil set_options(args) end end diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb index c545c1e47..dba9812a7 100644 --- a/lib/puppet/parser/ast/leaf.rb +++ b/lib/puppet/parser/ast/leaf.rb @@ -36,7 +36,7 @@ class Puppet::Parser::AST # Interpolate the string looking for variables, and then return # the result. def evaluate(scope) - return scope.strinterp(@value, @file, @line) + return scope.strinterp(@value, file, line) end end diff --git a/lib/puppet/parser/ast/resource_override.rb b/lib/puppet/parser/ast/resource_override.rb index 5c4a2410f..f8cf3a81e 100644 --- a/lib/puppet/parser/ast/resource_override.rb +++ b/lib/puppet/parser/ast/resource_override.rb @@ -40,8 +40,8 @@ class Puppet::Parser::AST :type => r.type, :title => r.title, :params => params, - :file => @file, - :line => @line, + :file => file, + :line => line, :source => scope.source, :scope => scope ) diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb index 2fdd78ddf..7f0e33359 100644 --- a/lib/puppet/parser/resource.rb +++ b/lib/puppet/parser/resource.rb @@ -4,13 +4,17 @@ class Puppet::Parser::Resource require 'puppet/parser/resource/param' require 'puppet/parser/resource/reference' require 'puppet/util/tagging' + require 'puppet/file_collection/lookup' + + include Puppet::FileCollection::Lookup + include Puppet::Util include Puppet::Util::MethodHelper include Puppet::Util::Errors include Puppet::Util::Logging include Puppet::Util::Tagging - attr_accessor :source, :line, :file, :scope, :rails_id + attr_accessor :source, :scope, :rails_id attr_accessor :virtual, :override, :translated attr_reader :exported, :evaluated, :params diff --git a/lib/puppet/parser/resource/param.rb b/lib/puppet/parser/resource/param.rb index 1a5cfe8fb..7ce58f4c4 100644 --- a/lib/puppet/parser/resource/param.rb +++ b/lib/puppet/parser/resource/param.rb @@ -1,10 +1,14 @@ +require 'puppet/file_collection/lookup' + # The parameters we stick in Resources. class Puppet::Parser::Resource::Param - attr_accessor :name, :value, :source, :line, :file, :add + attr_accessor :name, :value, :source, :add include Puppet::Util include Puppet::Util::Errors include Puppet::Util::MethodHelper + include Puppet::FileCollection::Lookup + def initialize(hash) set_options(hash) requiredopts(:name, :value, :source) diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb index cb505d606..bffc03788 100644 --- a/lib/puppet/parser/resource/reference.rb +++ b/lib/puppet/parser/resource/reference.rb @@ -1,7 +1,9 @@ require 'puppet/resource_reference' +require 'puppet/file_collection/lookup' # A reference to a resource. Mostly just the type and title. class Puppet::Parser::Resource::Reference < Puppet::ResourceReference + include Puppet::FileCollection::Lookup include Puppet::Util::MethodHelper include Puppet::Util::Errors diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index b57c74b95..5cb4ce13d 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -10,6 +10,7 @@ require 'puppet/util/errors' require 'puppet/util/log_paths' require 'puppet/util/logging' require 'puppet/resource_reference' +require 'puppet/file_collection/lookup' # see the bottom of the file for the rest of the inclusions @@ -19,6 +20,7 @@ class Type include Puppet::Util::Errors include Puppet::Util::LogPaths include Puppet::Util::Logging + include Puppet::FileCollection::Lookup ############################### # Code related to resource type attributes. @@ -2135,8 +2137,6 @@ class Type # In naming methods, I have tried to consistently name the method so # that it is clear whether it operates on all attributes (thus has 'attr' in # the method name, or whether it operates on a specific type of attributes. - attr_accessor :file, :line - attr_writer :title attr_writer :noop diff --git a/spec/unit/file_collection.rb b/spec/unit/file_collection.rb index e9acc8dd2..81bcc2d2d 100755 --- a/spec/unit/file_collection.rb +++ b/spec/unit/file_collection.rb @@ -42,4 +42,12 @@ describe Puppet::FileCollection do it "should return nil as the file name when an unknown index is provided" do @collection.path(50).should be_nil end + + it "should provide a global collection" do + Puppet::FileCollection.collection.should be_instance_of(Puppet::FileCollection) + end + + it "should reuse the global collection" do + Puppet::FileCollection.collection.should equal(Puppet::FileCollection.collection) + end end diff --git a/spec/unit/file_collection/lookup.rb b/spec/unit/file_collection/lookup.rb index 9ae7ae582..81cc61872 100755 --- a/spec/unit/file_collection/lookup.rb +++ b/spec/unit/file_collection/lookup.rb @@ -12,7 +12,7 @@ describe Puppet::FileCollection::Lookup do @tester = LookupTester.new @file_collection = mock 'file_collection' - @tester.stubs(:file_collection).returns @file_collection + Puppet::FileCollection.stubs(:collection).returns @file_collection end it "should use the file collection to determine the index of the file name" do @@ -38,4 +38,9 @@ describe Puppet::FileCollection::Lookup do @tester.line = 50 @tester.line.should == 50 end + + it "should default to the global file collection" do + Puppet::FileCollection.expects(:collection).returns "collection" + @tester.file_collection.should == "collection" + end end diff --git a/spec/unit/parser/ast.rb b/spec/unit/parser/ast.rb index 513943725..35e2b1eff 100644 --- a/spec/unit/parser/ast.rb +++ b/spec/unit/parser/ast.rb @@ -5,6 +5,10 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/parser/ast' describe Puppet::Parser::AST do + + it "should use the file lookup module" do + Puppet::Parser::AST.ancestors.should be_include(Puppet::FileCollection::Lookup) + end it "should have a doc accessor" do ast = Puppet::Parser::AST.new({}) @@ -34,4 +38,4 @@ describe Puppet::Parser::AST do end end -end
\ No newline at end of file +end diff --git a/spec/unit/parser/resource.rb b/spec/unit/parser/resource.rb index 63cfbc2ed..2666f6461 100755 --- a/spec/unit/parser/resource.rb +++ b/spec/unit/parser/resource.rb @@ -44,6 +44,10 @@ describe Puppet::Parser::Resource do end end + it "should use the file lookup module" do + Puppet::Parser::Resource.ancestors.should be_include(Puppet::FileCollection::Lookup) + end + it "should be isomorphic if it is builtin and models an isomorphic type" do Puppet::Type.type(:file).expects(:isomorphic?).returns(true) @resource = Puppet::Parser::Resource.new(:type => "file", :title => "whatever", :scope => @scope, :source => @source).isomorphic?.should be_true diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb index bb1452692..6284e67cc 100755 --- a/spec/unit/parser/resource/reference.rb +++ b/spec/unit/parser/resource/reference.rb @@ -7,6 +7,10 @@ describe Puppet::Parser::Resource::Reference do @type = Puppet::Parser::Resource::Reference end + it "should use the file lookup module" do + Puppet::Parser::Resource::Reference.ancestors.should be_include(Puppet::FileCollection::Lookup) + end + it "should require a type" do proc { @type.new(:title => "yay") }.should raise_error(Puppet::DevError) end |