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

Methods included from Util::Loggable

included, #logger, #slow_logger

Constructor Details

#initialize(name, klass, default = nil, strict = true, &validator_proc) ⇒ Coercible

Returns a new instance of Coercible.



217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/logstash/settings.rb', line 217

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)


244
245
246
# File 'lib/logstash/settings.rb', line 244

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

#set(value) ⇒ Object



236
237
238
239
240
241
242
# File 'lib/logstash/settings.rb', line 236

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