summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parameter
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/parameter
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/parameter')
-rw-r--r--lib/puppet/parameter/value.rb104
-rw-r--r--lib/puppet/parameter/value_collection.rb230
2 files changed, 167 insertions, 167 deletions
diff --git a/lib/puppet/parameter/value.rb b/lib/puppet/parameter/value.rb
index 3482c2c03..d9bfbafe2 100644
--- a/lib/puppet/parameter/value.rb
+++ b/lib/puppet/parameter/value.rb
@@ -2,62 +2,62 @@ require 'puppet/parameter/value_collection'
# An individual Value class.
class Puppet::Parameter::Value
- attr_reader :name, :options, :event
- attr_accessor :block, :call, :method, :required_features
-
- # Add an alias for this value.
- def alias(name)
- @aliases << convert(name)
- end
-
- # Return all aliases.
- def aliases
- @aliases.dup
- end
-
- # Store the event that our value generates, if it does so.
- def event=(value)
- @event = convert(value)
+ attr_reader :name, :options, :event
+ attr_accessor :block, :call, :method, :required_features
+
+ # Add an alias for this value.
+ def alias(name)
+ @aliases << convert(name)
+ end
+
+ # Return all aliases.
+ def aliases
+ @aliases.dup
+ end
+
+ # Store the event that our value generates, if it does so.
+ def event=(value)
+ @event = convert(value)
+ end
+
+ def initialize(name)
+ if name.is_a?(Regexp)
+ @name = name
+ else
+ # Convert to a string and then a symbol, so things like true/false
+ # still show up as symbols.
+ @name = convert(name)
end
- def initialize(name)
- if name.is_a?(Regexp)
- @name = name
- else
- # Convert to a string and then a symbol, so things like true/false
- # still show up as symbols.
- @name = convert(name)
- end
+ @aliases = []
- @aliases = []
+ @call = :instead
+ end
- @call = :instead
+ # Does a provided value match our value?
+ def match?(value)
+ if regex?
+ return true if name =~ value.to_s
+ else
+ return(name == convert(value) ? true : @aliases.include?(convert(value)))
end
-
- # Does a provided value match our value?
- def match?(value)
- if regex?
- return true if name =~ value.to_s
- else
- return(name == convert(value) ? true : @aliases.include?(convert(value)))
- end
- end
-
- # Is our value a regex?
- def regex?
- @name.is_a?(Regexp)
- end
-
- private
-
- # A standard way of converting all of our values, so we're always
- # comparing apples to apples.
- def convert(value)
- if value == ''
- # We can't intern an empty string, yay.
- value
- else
- value.to_s.to_sym
- end
+ end
+
+ # Is our value a regex?
+ def regex?
+ @name.is_a?(Regexp)
+ end
+
+ private
+
+ # A standard way of converting all of our values, so we're always
+ # comparing apples to apples.
+ def convert(value)
+ if value == ''
+ # We can't intern an empty string, yay.
+ value
+ else
+ value.to_s.to_sym
end
+ end
end
diff --git a/lib/puppet/parameter/value_collection.rb b/lib/puppet/parameter/value_collection.rb
index eabeb30f1..a9fd20233 100644
--- a/lib/puppet/parameter/value_collection.rb
+++ b/lib/puppet/parameter/value_collection.rb
@@ -4,140 +4,140 @@ require 'puppet/parameter/value'
# what values are allowed in a given parameter.
class Puppet::Parameter::ValueCollection
- def aliasvalue(name, other)
- other = other.to_sym
- unless value = match?(other)
- raise Puppet::DevError, "Cannot alias nonexistent value #{other}"
- end
-
- value.alias(name)
+ def aliasvalue(name, other)
+ other = other.to_sym
+ unless value = match?(other)
+ raise Puppet::DevError, "Cannot alias nonexistent value #{other}"
end
- # Return a doc string for all of the values in this parameter/property.
- def doc
- unless defined?(@doc)
- @doc = ""
- unless values.empty?
- @doc += " Valid values are "
- @doc += @strings.collect do |value|
- if aliases = value.aliases and ! aliases.empty?
- "``#{value.name}`` (also called ``#{aliases.join(", ")}``)"
- else
- "``#{value.name}``"
- end
- end.join(", ") + "."
- end
-
- @doc += " Values can match ``" + regexes.join("``, ``") + "``." unless regexes.empty?
- end
-
- @doc
+ value.alias(name)
+ end
+
+ # Return a doc string for all of the values in this parameter/property.
+ def doc
+ unless defined?(@doc)
+ @doc = ""
+ unless values.empty?
+ @doc += " Valid values are "
+ @doc += @strings.collect do |value|
+ if aliases = value.aliases and ! aliases.empty?
+ "``#{value.name}`` (also called ``#{aliases.join(", ")}``)"
+ else
+ "``#{value.name}``"
+ end
+ end.join(", ") + "."
+ end
+
+ @doc += " Values can match ``" + regexes.join("``, ``") + "``." unless regexes.empty?
end
- # Does this collection contain any value definitions?
- def empty?
- @values.empty?
+ @doc
+ end
+
+ # Does this collection contain any value definitions?
+ def empty?
+ @values.empty?
+ end
+
+ def initialize
+ # We often look values up by name, so a hash makes more sense.
+ @values = {}
+
+ # However, we want to retain the ability to match values in order,
+ # but we always prefer directly equality (i.e., strings) over regex matches.
+ @regexes = []
+ @strings = []
+ end
+
+ # Can we match a given value?
+ def match?(test_value)
+ # First look for normal values
+ if value = @strings.find { |v| v.match?(test_value) }
+ return value
end
- def initialize
- # We often look values up by name, so a hash makes more sense.
- @values = {}
-
- # However, we want to retain the ability to match values in order,
- # but we always prefer directly equality (i.e., strings) over regex matches.
- @regexes = []
- @strings = []
+ # Then look for a regex match
+ @regexes.find { |v| v.match?(test_value) }
+ end
+
+ # If the specified value is allowed, then munge appropriately.
+ def munge(value)
+ return value if empty?
+
+ if instance = match?(value)
+ if instance.regex?
+ return value
+ else
+ return instance.name
+ end
+ else
+ return value
end
-
- # Can we match a given value?
- def match?(test_value)
- # First look for normal values
- if value = @strings.find { |v| v.match?(test_value) }
- return value
- end
-
- # Then look for a regex match
- @regexes.find { |v| v.match?(test_value) }
+ end
+
+ # Define a new valid value for a property. You must provide the value itself,
+ # usually as a symbol, or a regex to match the value.
+ #
+ # The first argument to the method is either the value itself or a regex.
+ # The second argument is an option hash; valid options are:
+ # * <tt>:event</tt>: The event that should be returned when this value is set.
+ # * <tt>:call</tt>: When to call any associated block. The default value
+ # is ``instead``, which means to call the value instead of calling the
+ # provider. You can also specify ``before`` or ``after``, which will
+ # call both the block and the provider, according to the order you specify
+ # (the ``first`` refers to when the block is called, not the provider).
+ def newvalue(name, options = {}, &block)
+ value = Puppet::Parameter::Value.new(name)
+ @values[value.name] = value
+ if value.regex?
+ @regexes << value
+ else
+ @strings << value
end
- # If the specified value is allowed, then munge appropriately.
- def munge(value)
- return value if empty?
-
- if instance = match?(value)
- if instance.regex?
- return value
- else
- return instance.name
- end
- else
- return value
- end
+ options.each { |opt, arg| value.send(opt.to_s + "=", arg) }
+ if block_given?
+ value.block = block
+ else
+ value.call = options[:call] || :none
end
- # Define a new valid value for a property. You must provide the value itself,
- # usually as a symbol, or a regex to match the value.
- #
- # The first argument to the method is either the value itself or a regex.
- # The second argument is an option hash; valid options are:
- # * <tt>:event</tt>: The event that should be returned when this value is set.
- # * <tt>:call</tt>: When to call any associated block. The default value
- # is ``instead``, which means to call the value instead of calling the
- # provider. You can also specify ``before`` or ``after``, which will
- # call both the block and the provider, according to the order you specify
- # (the ``first`` refers to when the block is called, not the provider).
- def newvalue(name, options = {}, &block)
- value = Puppet::Parameter::Value.new(name)
- @values[value.name] = value
- if value.regex?
- @regexes << value
- else
- @strings << value
- end
-
- options.each { |opt, arg| value.send(opt.to_s + "=", arg) }
- if block_given?
- value.block = block
- else
- value.call = options[:call] || :none
- end
-
- value.method ||= "set_#{value.name}" if block_given? and ! value.regex?
-
- value
- end
+ value.method ||= "set_#{value.name}" if block_given? and ! value.regex?
- # Define one or more new values for our parameter.
- def newvalues(*names)
- names.each { |name| newvalue(name) }
- end
+ value
+ end
- def regexes
- @regexes.collect { |r| r.name.inspect }
- end
+ # Define one or more new values for our parameter.
+ def newvalues(*names)
+ names.each { |name| newvalue(name) }
+ end
- # Verify that the passed value is valid.
- def validate(value)
- return if empty?
+ def regexes
+ @regexes.collect { |r| r.name.inspect }
+ end
- unless @values.detect { |name, v| v.match?(value) }
- str = "Invalid value #{value.inspect}. "
+ # Verify that the passed value is valid.
+ def validate(value)
+ return if empty?
- str += "Valid values are #{values.join(", ")}. " unless values.empty?
+ unless @values.detect { |name, v| v.match?(value) }
+ str = "Invalid value #{value.inspect}. "
- str += "Valid values match #{regexes.join(", ")}." unless regexes.empty?
+ str += "Valid values are #{values.join(", ")}. " unless values.empty?
- raise ArgumentError, str
- end
- end
+ str += "Valid values match #{regexes.join(", ")}." unless regexes.empty?
- # Return a single value instance.
- def value(name)
- @values[name]
+ raise ArgumentError, str
end
+ end
- # Return the list of valid values.
- def values
- @strings.collect { |s| s.name }
- end
+ # Return a single value instance.
+ def value(name)
+ @values[name]
+ end
+
+ # Return the list of valid values.
+ def values
+ @strings.collect { |s| s.name }
+ end
end