Class: Puppet::Util::Settings::Setting
- Defined in:
- lib/vendor/puppet/util/settings/setting.rb
Overview
The base element type.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#call_on_define ⇒ Object
Returns the value of attribute call_on_define.
-
#default ⇒ Object
Returns the value of attribute default.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#section ⇒ Object
Returns the value of attribute section.
-
#setbycli ⇒ Object
Returns the value of attribute setbycli.
-
#short ⇒ Object
Returns the value of attribute short.
Instance Method Summary collapse
-
#getopt_args ⇒ Object
get the arguments in getopt format.
- #hook=(block) ⇒ Object
-
#initialize(args = {}) ⇒ Setting
constructor
Create the new element.
- #iscreated ⇒ Object
- #iscreated? ⇒ Boolean
-
#optparse_args ⇒ Object
get the arguments in OptionParser format.
- #set? ⇒ Boolean
-
#to_config ⇒ Object
Convert the object to a config statement.
-
#value ⇒ Object
Retrieves the value, or if it’s not set, retrieves the default.
Constructor Details
#initialize(args = {}) ⇒ Setting
Create the new element. Pretty much just sets the name.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 33 def initialize(args = {}) unless @settings = args.delete(:settings) raise ArgumentError.new("You must refer to a settings object") end args.each do |param, value| method = param.to_s + "=" raise ArgumentError, "#{self.class} does not accept #{param}" unless self.respond_to? method self.send(method, value) end raise ArgumentError, "You must provide a description for the #{self.name} config option" unless self.desc end |
Instance Attribute Details
#call_on_define ⇒ Object
Returns the value of attribute call_on_define.
3 4 5 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 3 def call_on_define @call_on_define end |
#default ⇒ Object
Returns the value of attribute default.
3 4 5 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 3 def default @default end |
#desc ⇒ Object
Returns the value of attribute desc.
4 5 6 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 4 def desc @desc end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 3 def name @name end |
#section ⇒ Object
Returns the value of attribute section.
3 4 5 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 3 def section @section end |
#setbycli ⇒ Object
Returns the value of attribute setbycli.
3 4 5 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 3 def setbycli @setbycli end |
#short ⇒ Object
Returns the value of attribute short.
4 5 6 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 4 def short @short end |
Instance Method Details
#getopt_args ⇒ Object
get the arguments in getopt format
11 12 13 14 15 16 17 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 11 def getopt_args if short [["--#{name}", "-#{short}", GetoptLong::REQUIRED_ARGUMENT]] else [["--#{name}", GetoptLong::REQUIRED_ARGUMENT]] end end |
#hook=(block) ⇒ Object
28 29 30 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 28 def hook=(block) :handle, &block end |
#iscreated ⇒ Object
48 49 50 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 48 def iscreated @iscreated = true end |
#iscreated? ⇒ Boolean
52 53 54 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 52 def iscreated? @iscreated end |
#optparse_args ⇒ Object
get the arguments in OptionParser format
20 21 22 23 24 25 26 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 20 def optparse_args if short ["--#{name}", "-#{short}", desc, :REQUIRED] else ["--#{name}", desc, :REQUIRED] end end |
#set? ⇒ Boolean
56 57 58 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 56 def set? !!(!@value.nil?) end |
#to_config ⇒ Object
Convert the object to a config statement.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 67 def to_config str = @desc.gsub(/^/, "# ") + "\n" # Add in a statement about the default. str += "# The default value is '#{@default}'.\n" if @default # If the value has not been overridden, then print it out commented # and unconverted, so it's clear that that's the default and how it # works. value = @settings.value(self.name) if value != @default line = "#{@name} = #{value}" else line = "# #{@name} = #{@default}" end str += line + "\n" str.gsub(/^/, " ") end |
#value ⇒ Object
Retrieves the value, or if it’s not set, retrieves the default.
90 91 92 |
# File 'lib/vendor/puppet/util/settings/setting.rb', line 90 def value @settings.value(self.name) end |