Class: Puppet::Settings::BaseSetting
- Defined in:
- lib/puppet/settings/base_setting.rb
Overview
The base setting type
Direct Known Subclasses
ArraySetting, BooleanSetting, CertificateRevocationSetting, DurationSetting, EnumSetting, PrioritySetting, StringSetting, SymbolicEnumSetting, TTLSetting, TerminusSetting
Instance Attribute Summary collapse
-
#call_hook ⇒ Object
Returns the value of attribute call_hook.
-
#default(check_application_defaults_first = false) ⇒ Object
Returns the value of attribute default.
-
#deprecated ⇒ Object
Returns the value of attribute deprecated.
-
#desc ⇒ Object
Returns the value of attribute desc.
-
#name ⇒ Object
Returns the value of attribute name.
-
#section ⇒ Object
Returns the value of attribute section.
-
#short ⇒ Object
Returns the value of attribute short.
Class Method Summary collapse
Instance Method Summary collapse
-
#allowed_on_commandline? ⇒ Boolean
True if we should raise a deprecation_warning if the setting is found in puppet.conf, but not if the user sets it on the commandline.
- #call_hook_on_define? ⇒ Boolean
- #call_hook_on_initialize? ⇒ Boolean
-
#completely_deprecated? ⇒ Boolean
True if we should raise a deprecation_warning if the setting is submitted on the commandline or is set in puppet.conf.
- #deprecated? ⇒ Boolean
-
#getopt_args ⇒ Object
get the arguments in getopt format.
- #has_hook? ⇒ Boolean
- #hook=(block) ⇒ Object
-
#initialize(args = {}) ⇒ BaseSetting
constructor
Create the new element.
- #inspect ⇒ Object
- #iscreated ⇒ Object
- #iscreated? ⇒ Boolean
-
#munge(value) ⇒ Object
Modify the value when it is first evaluated.
-
#optparse_args ⇒ Object
get the arguments in OptionParser format.
-
#print(value) ⇒ Object
Print the value for the user in a config compatible format.
- #set_meta(meta) ⇒ Object
-
#to_config ⇒ Object
Convert the object to a config statement.
-
#value(bypass_interpolation = false) ⇒ String
Retrieves the value, or if it’s not set, retrieves the default.
Constructor Details
#initialize(args = {}) ⇒ BaseSetting
Create the new element. Pretty much just sets the name.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/puppet/settings/base_setting.rb', line 61 def initialize(args = {}) unless @settings = args.delete(:settings) raise ArgumentError.new("You must refer to a settings object") end # explicitly set name prior to calling other param= methods to provide meaningful feedback during # other warnings @name = args[:name] if args.include? :name #set the default value for call_hook @call_hook = :on_write_only if args[:hook] and not args[:call_hook] @has_hook = false if args[:call_hook] and not args[:hook] #TRANSLATORS ':call_hook' and ':hook' are specific setting names and should not be translated raise ArgumentError, _("Cannot reference :call_hook for :%{name} if no :hook is defined") % { name: @name } end args.each do |param, value| method = param.to_s + "=" unless self.respond_to? method raise ArgumentError, _("%{class_name} (setting '%{setting}') does not accept %{parameter}") % { class_name: self.class, setting: args[:name], parameter: param } end self.send(method, value) end unless self.desc raise ArgumentError, _("You must provide a description for the %{class_name} config option") % { class_name: self.name } end end |
Instance Attribute Details
#call_hook ⇒ Object
Returns the value of attribute call_hook.
5 6 7 |
# File 'lib/puppet/settings/base_setting.rb', line 5 def call_hook @call_hook end |
#default(check_application_defaults_first = false) ⇒ Object
Returns the value of attribute default.
5 6 7 |
# File 'lib/puppet/settings/base_setting.rb', line 5 def default @default end |
#deprecated ⇒ Object
Returns the value of attribute deprecated.
6 7 8 |
# File 'lib/puppet/settings/base_setting.rb', line 6 def deprecated @deprecated end |
#desc ⇒ Object
Returns the value of attribute desc.
5 6 7 |
# File 'lib/puppet/settings/base_setting.rb', line 5 def desc @desc end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/puppet/settings/base_setting.rb', line 5 def name @name end |
#section ⇒ Object
Returns the value of attribute section.
5 6 7 |
# File 'lib/puppet/settings/base_setting.rb', line 5 def section @section end |
#short ⇒ Object
Returns the value of attribute short.
6 7 8 |
# File 'lib/puppet/settings/base_setting.rb', line 6 def short @short end |
Class Method Details
.available_call_hook_values ⇒ Object
8 9 10 |
# File 'lib/puppet/settings/base_setting.rb', line 8 def self.available_call_hook_values [:on_define_and_write, :on_initialize_and_write, :on_write_only] end |
Instance Method Details
#allowed_on_commandline? ⇒ Boolean
True if we should raise a deprecation_warning if the setting is found in puppet.conf, but not if the user sets it on the commandline
190 191 192 |
# File 'lib/puppet/settings/base_setting.rb', line 190 def allowed_on_commandline? @deprecated == :allowed_on_commandline end |
#call_hook_on_define? ⇒ Boolean
25 26 27 |
# File 'lib/puppet/settings/base_setting.rb', line 25 def call_hook_on_define? call_hook == :on_define_and_write end |
#call_hook_on_initialize? ⇒ Boolean
29 30 31 |
# File 'lib/puppet/settings/base_setting.rb', line 29 def call_hook_on_initialize? call_hook == :on_initialize_and_write end |
#completely_deprecated? ⇒ Boolean
True if we should raise a deprecation_warning if the setting is submitted on the commandline or is set in puppet.conf.
184 185 186 |
# File 'lib/puppet/settings/base_setting.rb', line 184 def completely_deprecated? @deprecated == :completely end |
#deprecated? ⇒ Boolean
178 179 180 |
# File 'lib/puppet/settings/base_setting.rb', line 178 def deprecated? !!@deprecated end |
#getopt_args ⇒ Object
get the arguments in getopt format
34 35 36 37 38 39 40 |
# File 'lib/puppet/settings/base_setting.rb', line 34 def getopt_args if short [["--#{name}", "-#{short}", GetoptLong::REQUIRED_ARGUMENT]] else [["--#{name}", GetoptLong::REQUIRED_ARGUMENT]] end end |
#has_hook? ⇒ Boolean
56 57 58 |
# File 'lib/puppet/settings/base_setting.rb', line 56 def has_hook? @has_hook end |
#hook=(block) ⇒ Object
51 52 53 54 |
# File 'lib/puppet/settings/base_setting.rb', line 51 def hook=(block) @has_hook = true :handle, &block end |
#inspect ⇒ Object
194 195 196 |
# File 'lib/puppet/settings/base_setting.rb', line 194 def inspect %Q{<#{self.class}:#{self.object_id} @name="#{@name}" @section="#{@section}" @default="#{@default}" @call_hook="#{@call_hook}">} end |
#iscreated ⇒ Object
93 94 95 |
# File 'lib/puppet/settings/base_setting.rb', line 93 def iscreated @iscreated = true end |
#iscreated? ⇒ Boolean
97 98 99 |
# File 'lib/puppet/settings/base_setting.rb', line 97 def iscreated? @iscreated end |
#munge(value) ⇒ Object
Modify the value when it is first evaluated
156 157 158 |
# File 'lib/puppet/settings/base_setting.rb', line 156 def munge(value) value end |
#optparse_args ⇒ Object
get the arguments in OptionParser format
43 44 45 46 47 48 49 |
# File 'lib/puppet/settings/base_setting.rb', line 43 def optparse_args if short ["--#{name}", "-#{short}", desc, :REQUIRED] else ["--#{name}", desc, :REQUIRED] end end |
#print(value) ⇒ Object
Print the value for the user in a config compatible format
161 162 163 |
# File 'lib/puppet/settings/base_setting.rb', line 161 def print(value) munge(value) end |
#set_meta(meta) ⇒ Object
165 166 167 |
# File 'lib/puppet/settings/base_setting.rb', line 165 def () Puppet.notice("#{name} does not support meta data. Ignoring.") end |
#to_config ⇒ Object
Convert the object to a config statement.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/puppet/settings/base_setting.rb', line 122 def to_config require 'puppet/util/docs' # Scrub any funky indentation; comment out description. str = Puppet::Util::Docs.scrub(@desc).gsub(/^/, "# ") + "\n" # Add in a statement about the default. str << "# The default value is '#{default(true)}'.\n" if default(true) # 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") # Indent str.gsub(/^/, " ") end |
#value(bypass_interpolation = false) ⇒ String
Returns Retrieves the value, or if it’s not set, retrieves the default.
151 152 153 |
# File 'lib/puppet/settings/base_setting.rb', line 151 def value(bypass_interpolation = false) @settings.value(self.name, nil, bypass_interpolation) end |