The base setting type
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
# File lib/puppet/settings/base_setting.rb, line 192 def allowed_on_commandline? @deprecated == :allowed_on_commandline end
# File lib/puppet/settings/base_setting.rb, line 27 def call_hook=(value) if value.nil? Puppet.warning "Setting :#{name} :call_hook is nil, defaulting to :on_write_only" value ||= :on_write_only end raise ArgumentError, "Invalid option #{value} for call_hook" unless self.class.available_call_hook_values.include? value @call_hook = value end
# File lib/puppet/settings/base_setting.rb, line 36 def call_hook_on_define? call_hook == :on_define_and_write end
# File lib/puppet/settings/base_setting.rb, line 40 def call_hook_on_initialize? call_hook == :on_initialize_and_write end
# File lib/puppet/settings/base_setting.rb, line 17 def call_on_define=(value) if value Puppet.deprecation_warning ":call_on_define has been changed to :call_hook => :on_define_and_write. Please change #{name}." @call_hook = :on_define_and_write else Puppet.deprecation_warning ":call_on_define => :false has been changed to :call_hook => :on_write_only. Please change #{name}." @call_hook = :on_write_only end end
True if we should raise a deprecation_warning if the setting is submitted on the commandline or is set in puppet.conf.
# File lib/puppet/settings/base_setting.rb, line 186 def completely_deprecated? @deprecated == :completely end
# File lib/puppet/settings/base_setting.rb, line 175 def deprecated=(deprecation) raise(ArgumentError, "'#{deprecation}' is an unknown setting deprecation state. Must be either :completely or :allowed_on_commandline") unless [:completely, :allowed_on_commandline].include?(deprecation) @deprecated = deprecation end
# File lib/puppet/settings/base_setting.rb, line 180 def deprecated? !!@deprecated end
get the arguments in getopt format
# File lib/puppet/settings/base_setting.rb, line 58 def getopt_args if short [["--#{name}", "-#{short}", GetoptLong::REQUIRED_ARGUMENT]] else [["--#{name}", GetoptLong::REQUIRED_ARGUMENT]] end end
# File lib/puppet/settings/base_setting.rb, line 80 def has_hook? @has_hook end
# File lib/puppet/settings/base_setting.rb, line 75 def hook=(block) @has_hook = true meta_def :handle, &block end
# File lib/puppet/settings/base_setting.rb, line 110 def iscreated @iscreated = true end
# File lib/puppet/settings/base_setting.rb, line 114 def iscreated? @iscreated end
Modify the value when it is first evaluated
# File lib/puppet/settings/base_setting.rb, line 167 def munge(value) value end
get the arguments in OptionParser format
# File lib/puppet/settings/base_setting.rb, line 67 def optparse_args if short ["--#{name}", "-#{short}", desc, :REQUIRED] else ["--#{name}", desc, :REQUIRED] end end
# File lib/puppet/settings/base_setting.rb, line 171 def set_meta(meta) Puppet.notice("#{name} does not support meta data. Ignoring.") end
added as a proper method, only to generate a deprecation warning and return value from
# File lib/puppet/settings/base_setting.rb, line 46 def setbycli Puppet.deprecation_warning "Puppet.settings.setting(#{name}).setbycli is deprecated. Use Puppet.settings.set_by_cli?(#{name}) instead." @settings.set_by_cli?(name) end
# File lib/puppet/settings/base_setting.rb, line 51 def setbycli=(value) Puppet.deprecation_warning "Puppet.settings.setting(#{name}).setbycli= is deprecated. You should not manually set that values were specified on the command line." @settings.set_value(name, @settings[name], :cli) if value raise ArgumentError, "Cannot unset setbycli" unless value end
short name for the celement
# File lib/puppet/settings/base_setting.rb, line 119 def short=(value) raise ArgumentError, "Short names can only be one character." if value.to_s.length != 1 @short = value.to_s end
Convert the object to a config statement.
# File lib/puppet/settings/base_setting.rb, line 133 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
@param bypass_interpolation [Boolean] Set this true to skip the
interpolation step, returning the raw setting value. Defaults to false.
@return [String] Retrieves the value, or if it’s not set, retrieves the default. @api public
# File lib/puppet/settings/base_setting.rb, line 162 def value(bypass_interpolation = false) @settings.value(self.name, nil, bypass_interpolation) end
# 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
Create the new element. Pretty much just sets the name.
# File lib/puppet/settings/base_setting.rb, line 85 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 raise ArgumentError, "Cannot reference :call_hook for :#{@name} if no :hook is defined" if args[:call_hook] and not args[:hook] args.each do |param, value| method = param.to_s + "=" raise ArgumentError, "#{self.class} (setting '#{args[:name]}') 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