Class: LogStash::Setting::Coercible

Inherits:
LogStash::Setting show all
Defined in:
lib/logstash/settings.rb

Instance Attribute Summary

Attributes inherited from LogStash::Setting

#default, #name

Instance Method Summary collapse

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.



244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/logstash/settings.rb', line 244

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

Raises:

  • (NotImplementedError)


271
272
273
# File 'lib/logstash/settings.rb', line 271

def coerce(value)
  raise NotImplementedError.new("Please implement #coerce for #{self.class}")
end

#set(value) ⇒ Object



263
264
265
266
267
268
269
# File 'lib/logstash/settings.rb', line 263

def set(value)
  coerced_value = coerce(value)
  validate(coerced_value)
  @value = coerce(coerced_value)
  @value_is_set = true
  @value
end