Class: Puppet::Settings::BaseSetting
- Inherits:
-
Object
- Object
- Puppet::Settings::BaseSetting
show all
- Defined in:
- lib/puppet/settings/base_setting.rb
Overview
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args = {}) ⇒ BaseSetting
Create the new element. Pretty much just sets the name.
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# 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
@name = args[:name] if args.include? :name
@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
|
Instance Attribute Details
#call_hook ⇒ Object
5
6
7
|
# File 'lib/puppet/settings/base_setting.rb', line 5
def call_hook
@call_hook
end
|
#call_on_define ⇒ Object
5
6
7
|
# File 'lib/puppet/settings/base_setting.rb', line 5
def call_on_define
@call_on_define
end
|
#default(check_application_defaults_first = false) ⇒ Object
5
6
7
|
# File 'lib/puppet/settings/base_setting.rb', line 5
def default
@default
end
|
#deprecated ⇒ Object
6
7
8
|
# File 'lib/puppet/settings/base_setting.rb', line 6
def deprecated
@deprecated
end
|
5
6
7
|
# File 'lib/puppet/settings/base_setting.rb', line 5
def desc
@desc
end
|
5
6
7
|
# File 'lib/puppet/settings/base_setting.rb', line 5
def name
@name
end
|
5
6
7
|
# File 'lib/puppet/settings/base_setting.rb', line 5
def section
@section
end
|
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
192
193
194
|
# File 'lib/puppet/settings/base_setting.rb', line 192
def allowed_on_commandline?
@deprecated == :allowed_on_commandline
end
|
#call_hook_on_define? ⇒ Boolean
36
37
38
|
# File 'lib/puppet/settings/base_setting.rb', line 36
def call_hook_on_define?
call_hook == :on_define_and_write
end
|
#call_hook_on_initialize? ⇒ Boolean
40
41
42
|
# File 'lib/puppet/settings/base_setting.rb', line 40
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.
186
187
188
|
# File 'lib/puppet/settings/base_setting.rb', line 186
def completely_deprecated?
@deprecated == :completely
end
|
#deprecated? ⇒ Boolean
180
181
182
|
# File 'lib/puppet/settings/base_setting.rb', line 180
def deprecated?
!!@deprecated
end
|
#getopt_args ⇒ Object
get the arguments in getopt format
58
59
60
61
62
63
64
|
# 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
|
#has_hook? ⇒ Boolean
80
81
82
|
# File 'lib/puppet/settings/base_setting.rb', line 80
def has_hook?
@has_hook
end
|
#hook=(block) ⇒ Object
75
76
77
78
|
# File 'lib/puppet/settings/base_setting.rb', line 75
def hook=(block)
@has_hook = true
meta_def :handle, &block
end
|
#iscreated ⇒ Object
110
111
112
|
# File 'lib/puppet/settings/base_setting.rb', line 110
def iscreated
@iscreated = true
end
|
#iscreated? ⇒ Boolean
114
115
116
|
# File 'lib/puppet/settings/base_setting.rb', line 114
def iscreated?
@iscreated
end
|
#munge(value) ⇒ Object
Modify the value when it is first evaluated
167
168
169
|
# File 'lib/puppet/settings/base_setting.rb', line 167
def munge(value)
value
end
|
#optparse_args ⇒ Object
get the arguments in OptionParser format
67
68
69
70
71
72
73
|
# File 'lib/puppet/settings/base_setting.rb', line 67
def optparse_args
if short
["--#{name}", "-#{short}", desc, :REQUIRED]
else
["--#{name}", desc, :REQUIRED]
end
end
|
171
172
173
|
# 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
46
47
48
49
|
# 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
|
#setbycli=(value) ⇒ Object
51
52
53
54
55
|
# 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
|
#to_config ⇒ Object
Convert the object to a config statement.
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/puppet/settings/base_setting.rb', line 133
def to_config
require 'puppet/util/docs'
str = Puppet::Util::Docs.scrub(@desc).gsub(/^/, "# ") + "\n"
str << "# The default value is '#{default(true)}'.\n" if default(true)
value = @settings.value(self.name)
if value != @default
line = "#{@name} = #{value}"
else
line = "# #{@name} = #{@default}"
end
str << (line + "\n")
str.gsub(/^/, " ")
end
|
#value(bypass_interpolation = false) ⇒ String
Returns Retrieves the value, or if it’s not set, retrieves the default.
162
163
164
|
# File 'lib/puppet/settings/base_setting.rb', line 162
def value(bypass_interpolation = false)
@settings.value(self.name, nil, bypass_interpolation)
end
|