Class: LogStash::Setting
- Inherits:
-
Object
- Object
- LogStash::Setting
- Includes:
- Util::Loggable
- Defined in:
- lib/logstash/settings.rb
Direct Known Subclasses
Coercible, ExistingFilePath, String, Validator, WritableDirectory
Defined Under Namespace
Classes: ArrayCoercible, Boolean, Bytes, Coercible, ExistingFilePath, Integer, NullableString, Numeric, Port, PortRange, PositiveInteger, SplittableStringArray, String, TimeValue, Validator, WritableDirectory
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, klass, default = nil, strict = true, &validator_proc) ⇒ Setting
constructor
A new instance of Setting.
- #reset ⇒ Object
- #set(value) ⇒ Object
- #set? ⇒ Boolean
- #strict? ⇒ Boolean
- #to_hash ⇒ Object
- #validate_value ⇒ Object
- #value ⇒ Object
Methods included from Util::Loggable
included, #logger, #slow_logger
Constructor Details
#initialize(name, klass, default = nil, strict = true, &validator_proc) ⇒ Setting
Returns a new instance of Setting.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/logstash/settings.rb', line 163 def initialize(name, klass, default=nil, strict=true, &validator_proc) @name = name unless klass.is_a?(Class) raise ArgumentError.new("Setting \"#{@name}\" must be initialized with a class (received #{klass})") end @klass = klass @validator_proc = validator_proc @value = nil @value_is_set = false @strict = strict validate(default) if @strict @default = default end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
161 162 163 |
# File 'lib/logstash/settings.rb', line 161 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
161 162 163 |
# File 'lib/logstash/settings.rb', line 161 def name @name end |
Instance Method Details
#==(other) ⇒ Object
217 218 219 |
# File 'lib/logstash/settings.rb', line 217 def ==(other) self.to_hash == other.to_hash end |
#reset ⇒ Object
197 198 199 200 |
# File 'lib/logstash/settings.rb', line 197 def reset @value = nil @value_is_set = false end |
#set(value) ⇒ Object
190 191 192 193 194 195 |
# File 'lib/logstash/settings.rb', line 190 def set(value) validate(value) if @strict @value = value @value_is_set = true @value end |
#to_hash ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/logstash/settings.rb', line 202 def to_hash { "name" => @name, "klass" => @klass, "value" => @value, "value_is_set" => @value_is_set, "default" => @default, # Proc#== will only return true if it's the same obj # so no there's no point in comparing it # also thereÅ› no use case atm to return the proc # so let's not expose it #"validator_proc" => @validator_proc } end |
#validate_value ⇒ Object
221 222 223 |
# File 'lib/logstash/settings.rb', line 221 def validate_value validate(value) end |
#value ⇒ Object
178 179 180 |
# File 'lib/logstash/settings.rb', line 178 def value @value_is_set ? @value : default end |