Class: LogStash::Setting::Coercible
- Inherits:
-
LogStash::Setting
- Object
- LogStash::Setting
- LogStash::Setting::Coercible
- Defined in:
- lib/logstash/settings.rb
Direct Known Subclasses
ArrayCoercible, Boolean, Bytes, Integer, Modules, Numeric, PortRange, TimeValue
Instance Attribute Summary
Attributes inherited from LogStash::Setting
Instance Method Summary collapse
- #coerce(value) ⇒ Object
-
#initialize(name, klass, default = nil, strict = true, &validator_proc) ⇒ Coercible
constructor
A new instance of Coercible.
- #set(value) ⇒ Object
Methods inherited from LogStash::Setting
#==, #reset, #set?, #strict?, #to_hash, #validate_value, #value
Constructor Details
#initialize(name, klass, default = nil, strict = true, &validator_proc) ⇒ Coercible
Returns a new instance of Coercible.
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/logstash/settings.rb', line 286 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 if strict coerced_default = coerce(default) validate(coerced_default) @default = coerced_default else @default = default end end |
Instance Method Details
#coerce(value) ⇒ Object
313 314 315 |
# File 'lib/logstash/settings.rb', line 313 def coerce(value) raise NotImplementedError.new("Please implement #coerce for #{self.class}") end |
#set(value) ⇒ Object
305 306 307 308 309 310 311 |
# File 'lib/logstash/settings.rb', line 305 def set(value) coerced_value = coerce(value) validate(coerced_value) @value = coerce(coerced_value) @value_is_set = true @value end |