summaryrefslogtreecommitdiffstats
path: root/lib/puppet/node
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:12:17 -0700
commit3180b9d9b2c844dade1d361326600f7001ec66dd (patch)
tree98fe7c5ac7eb942aac9c39f019a17b0b3f5a57f4 /lib/puppet/node
parent543225970225de5697734bfaf0a6eee996802c04 (diff)
downloadpuppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.gz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.tar.xz
puppet-3180b9d9b2c844dade1d361326600f7001ec66dd.zip
Code smell: Two space indentation
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
Diffstat (limited to 'lib/puppet/node')
-rw-r--r--lib/puppet/node/environment.rb200
-rwxr-xr-xlib/puppet/node/facts.rb94
2 files changed, 147 insertions, 147 deletions
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index 4f3ef2dad..44c764025 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -7,124 +7,124 @@ end
# Model the environment that a node can operate in. This class just
# provides a simple wrapper for the functionality around environments.
class Puppet::Node::Environment
- module Helper
- def environment
- Puppet::Node::Environment.new(@environment)
- end
-
- def environment=(env)
- if env.is_a?(String) or env.is_a?(Symbol)
- @environment = env
- else
- @environment = env.name
- end
- end
+ module Helper
+ def environment
+ Puppet::Node::Environment.new(@environment)
end
- include Puppet::Util::Cacher
-
- @seen = {}
+ def environment=(env)
+ if env.is_a?(String) or env.is_a?(Symbol)
+ @environment = env
+ else
+ @environment = env.name
+ end
+ end
+ end
- # Return an existing environment instance, or create a new one.
- def self.new(name = nil)
- return name if name.is_a?(self)
- name ||= Puppet.settings.value(:environment)
+ include Puppet::Util::Cacher
- raise ArgumentError, "Environment name must be specified" unless name
+ @seen = {}
- symbol = name.to_sym
+ # Return an existing environment instance, or create a new one.
+ def self.new(name = nil)
+ return name if name.is_a?(self)
+ name ||= Puppet.settings.value(:environment)
- return @seen[symbol] if @seen[symbol]
+ raise ArgumentError, "Environment name must be specified" unless name
- obj = self.allocate
- obj.send :initialize, symbol
- @seen[symbol] = obj
- end
-
- def self.current
- Thread.current[:environment] || root
- end
-
- def self.current=(env)
- Thread.current[:environment] = new(env)
- end
-
- def self.root
- @root
- end
+ symbol = name.to_sym
- # This is only used for testing.
- def self.clear
- @seen.clear
- end
+ return @seen[symbol] if @seen[symbol]
- attr_reader :name
+ obj = self.allocate
+ obj.send :initialize, symbol
+ @seen[symbol] = obj
+ end
- # Return an environment-specific setting.
- def [](param)
- Puppet.settings.value(param, self.name)
- end
+ def self.current
+ Thread.current[:environment] || root
+ end
- def initialize(name)
- @name = name
- end
+ def self.current=(env)
+ Thread.current[:environment] = new(env)
+ end
- def known_resource_types
- if @known_resource_types.nil? or @known_resource_types.stale?
- @known_resource_types = Puppet::Resource::TypeCollection.new(self)
- @known_resource_types.perform_initial_import
- end
- @known_resource_types
- end
+ def self.root
+ @root
+ end
- def module(name)
- mod = Puppet::Module.new(name, self)
- return nil unless mod.exist?
- mod
- end
+ # This is only used for testing.
+ def self.clear
+ @seen.clear
+ end
- # Cache the modulepath, so that we aren't searching through
- # all known directories all the time.
- cached_attr(:modulepath, :ttl => Puppet[:filetimeout]) do
- dirs = self[:modulepath].split(File::PATH_SEPARATOR)
- dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs if ENV["PUPPETLIB"]
- validate_dirs(dirs)
- end
+ attr_reader :name
- # Return all modules from this environment.
- # Cache the list, because it can be expensive to create.
- cached_attr(:modules, :ttl => Puppet[:filetimeout]) do
- module_names = modulepath.collect { |path| Dir.entries(path) }.flatten.uniq
- module_names.collect do |path|
- begin
- Puppet::Module.new(path, self)
- rescue Puppet::Module::Error => e
- nil
- end
- end.compact
- end
+ # Return an environment-specific setting.
+ def [](param)
+ Puppet.settings.value(param, self.name)
+ end
- # Cache the manifestdir, so that we aren't searching through
- # all known directories all the time.
- cached_attr(:manifestdir, :ttl => Puppet[:filetimeout]) do
- validate_dirs(self[:manifestdir].split(File::PATH_SEPARATOR))
- end
+ def initialize(name)
+ @name = name
+ end
- def to_s
- name.to_s
+ def known_resource_types
+ if @known_resource_types.nil? or @known_resource_types.stale?
+ @known_resource_types = Puppet::Resource::TypeCollection.new(self)
+ @known_resource_types.perform_initial_import
end
-
- def validate_dirs(dirs)
- dirs.collect do |dir|
- if dir !~ /^#{File::SEPARATOR}/
- File.join(Dir.getwd, dir)
- else
- dir
- end
- end.find_all do |p|
- p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p)
- end
+ @known_resource_types
+ end
+
+ def module(name)
+ mod = Puppet::Module.new(name, self)
+ return nil unless mod.exist?
+ mod
+ end
+
+ # Cache the modulepath, so that we aren't searching through
+ # all known directories all the time.
+ cached_attr(:modulepath, :ttl => Puppet[:filetimeout]) do
+ dirs = self[:modulepath].split(File::PATH_SEPARATOR)
+ dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs if ENV["PUPPETLIB"]
+ validate_dirs(dirs)
+ end
+
+ # Return all modules from this environment.
+ # Cache the list, because it can be expensive to create.
+ cached_attr(:modules, :ttl => Puppet[:filetimeout]) do
+ module_names = modulepath.collect { |path| Dir.entries(path) }.flatten.uniq
+ module_names.collect do |path|
+ begin
+ Puppet::Module.new(path, self)
+ rescue Puppet::Module::Error => e
+ nil
+ end
+ end.compact
+ end
+
+ # Cache the manifestdir, so that we aren't searching through
+ # all known directories all the time.
+ cached_attr(:manifestdir, :ttl => Puppet[:filetimeout]) do
+ validate_dirs(self[:manifestdir].split(File::PATH_SEPARATOR))
+ end
+
+ def to_s
+ name.to_s
+ end
+
+ def validate_dirs(dirs)
+ dirs.collect do |dir|
+ if dir !~ /^#{File::SEPARATOR}/
+ File.join(Dir.getwd, dir)
+ else
+ dir
+ end
+ end.find_all do |p|
+ p =~ /^#{File::SEPARATOR}/ && FileTest.directory?(p)
end
+ end
- @root = new(:'*root*')
+ @root = new(:'*root*')
end
diff --git a/lib/puppet/node/facts.rb b/lib/puppet/node/facts.rb
index 0b9fc5879..b77ad22d5 100755
--- a/lib/puppet/node/facts.rb
+++ b/lib/puppet/node/facts.rb
@@ -4,67 +4,67 @@ require 'puppet/indirector'
# Manage a given node's facts. This either accepts facts and stores them, or
# returns facts for a given node.
class Puppet::Node::Facts
- # Set up indirection, so that nodes can be looked for in
- # the node sources.
- extend Puppet::Indirector
+ # Set up indirection, so that nodes can be looked for in
+ # the node sources.
+ extend Puppet::Indirector
- # We want to expire any cached nodes if the facts are saved.
- module NodeExpirer
- def save(key, instance)
- Puppet::Node.expire(instance.name)
- super
- end
+ # We want to expire any cached nodes if the facts are saved.
+ module NodeExpirer
+ def save(key, instance)
+ Puppet::Node.expire(instance.name)
+ super
end
+ end
- indirects :facts, :terminus_setting => :facts_terminus, :extend => NodeExpirer
+ indirects :facts, :terminus_setting => :facts_terminus, :extend => NodeExpirer
- attr_accessor :name, :values
+ attr_accessor :name, :values
- def add_local_facts
- values["clientcert"] = Puppet.settings[:certname]
- values["clientversion"] = Puppet.version.to_s
- values["environment"] ||= Puppet.settings[:environment]
- end
+ def add_local_facts
+ values["clientcert"] = Puppet.settings[:certname]
+ values["clientversion"] = Puppet.version.to_s
+ values["environment"] ||= Puppet.settings[:environment]
+ end
- def initialize(name, values = {})
- @name = name
- @values = values
+ def initialize(name, values = {})
+ @name = name
+ @values = values
- add_internal
- end
+ add_internal
+ end
- def downcase_if_necessary
- return unless Puppet.settings[:downcasefacts]
+ def downcase_if_necessary
+ return unless Puppet.settings[:downcasefacts]
- Puppet.warning "DEPRECATION NOTICE: Fact downcasing is deprecated; please disable (20080122)"
- values.each do |fact, value|
- values[fact] = value.downcase if value.is_a?(String)
- end
+ Puppet.warning "DEPRECATION NOTICE: Fact downcasing is deprecated; please disable (20080122)"
+ values.each do |fact, value|
+ values[fact] = value.downcase if value.is_a?(String)
end
+ end
- # Convert all fact values into strings.
- def stringify
- values.each do |fact, value|
- values[fact] = value.to_s
- end
+ # Convert all fact values into strings.
+ def stringify
+ values.each do |fact, value|
+ values[fact] = value.to_s
end
+ end
- def ==(other)
- return false unless self.name == other.name
- strip_internal == other.send(:strip_internal)
- end
+ def ==(other)
+ return false unless self.name == other.name
+ strip_internal == other.send(:strip_internal)
+ end
- private
+ private
- # Add internal data to the facts for storage.
- def add_internal
- self.values[:_timestamp] = Time.now
- end
+ # Add internal data to the facts for storage.
+ def add_internal
+ self.values[:_timestamp] = Time.now
+ end
- # Strip out that internal data.
- def strip_internal
- newvals = values.dup
- newvals.find_all { |name, value| name.to_s =~ /^_/ }.each { |name, value| newvals.delete(name) }
- newvals
- end
+ # Strip out that internal data.
+ def strip_internal
+ newvals = values.dup
+ newvals.find_all { |name, value| name.to_s =~ /^_/ }.each { |name, value| newvals.delete(name) }
+ newvals
+ end
end