# class Puppet::Settings::BaseSetting

The base setting type

### Attributes

call_hook[RW]
call_on_define[RW]
default[RW]
desc[R]
name[RW]
section[RW]
short[R]

### Public Class Methods

available_call_hook_values() click to toggle source

    # 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

new(args = {}) click to toggle source

Create the new element. Pretty much just sets the name.

    # File lib/puppet/settings/base_setting.rb, line 88
    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]

      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

### Public Instance Methods

call_hook=(value) click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 31
    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

call_hook_on_define?() click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 40
    def call_hook_on_define?
      call_hook == :on_define_and_write
    end

call_hook_on_initialize?() click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 44
    def call_hook_on_initialize?
      call_hook == :on_initialize_and_write
    end

call_on_define=(value) click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 21
    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

desc=(value) click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 12
    def desc=(value)
      @desc = value.gsub(/^\s*/, '')
    end

getopt_args() click to toggle source

get the arguments in getopt format

    # File lib/puppet/settings/base_setting.rb, line 62
    def getopt_args
      if short
        [["--#{name}", "-#{short}", GetoptLong::REQUIRED_ARGUMENT]]
      else
        [["--#{name}", GetoptLong::REQUIRED_ARGUMENT]]
      end
    end

has_hook?() click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 79
    def has_hook?
      respond_to? :handle
    end

hook=(block) click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 83
    def hook=(block)
      meta_def :handle, &block
    end

iscreated() click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 112
    def iscreated
      @iscreated = true
    end

iscreated?() click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 116
    def iscreated?
      @iscreated
    end

munge(value) click to toggle source

Modify the value when it is first evaluated

    # File lib/puppet/settings/base_setting.rb, line 160
    def munge(value)
      value
    end

optparse_args() click to toggle source

get the arguments in OptionParser format

    # File lib/puppet/settings/base_setting.rb, line 71
    def optparse_args
      if short
        ["--#{name}", "-#{short}", desc, :REQUIRED]
      else
        ["--#{name}", desc, :REQUIRED]
      end
    end

setbycli() click to toggle source

added as a proper method, only to generate a deprecation warning and return value from

    # File lib/puppet/settings/base_setting.rb, line 50
    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

setbycli=(value) click to toggle source

    # File lib/puppet/settings/base_setting.rb, line 55
    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=(value) click to toggle source

short name for the celement

    # File lib/puppet/settings/base_setting.rb, line 121
    def short=(value)
      raise ArgumentError, "Short names can only be one character." if value.to_s.length != 1
      @short = value.to_s
    end

to_config() click to toggle source

Convert the object to a config statement.

    # File lib/puppet/settings/base_setting.rb, line 132
    def to_config
      str = @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"

      str.gsub(/^/, "    ")
    end

value() click to toggle source

Retrieves the value, or if it’s not set, retrieves the default.

    # File lib/puppet/settings/base_setting.rb, line 155
    def value
      @settings.value(self.name)
    end