Class: LogStash::Setting

Inherits:
Object
  • Object
show all
Includes:
Util::Loggable
Defined in:
lib/logstash/settings.rb

Defined Under Namespace

Classes: ArrayCoercible, Boolean, Bytes, Coercible, DeprecatedAndRenamed, DeprecatedSetting, ExistingFilePath, Integer, Modules, NullableString, Numeric, Port, PortRange, PositiveInteger, SplittableStringArray, String, TimeValue, Validator, WritableDirectory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Setting.



212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/logstash/settings.rb', line 212

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

#defaultObject (readonly)

Returns the value of attribute default.



210
211
212
# File 'lib/logstash/settings.rb', line 210

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



210
211
212
# File 'lib/logstash/settings.rb', line 210

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



266
267
268
# File 'lib/logstash/settings.rb', line 266

def ==(other)
  self.to_hash == other.to_hash
end

#resetObject



246
247
248
249
# File 'lib/logstash/settings.rb', line 246

def reset
  @value = nil
  @value_is_set = false
end

#set(value) ⇒ Object



239
240
241
242
243
244
# File 'lib/logstash/settings.rb', line 239

def set(value)
  validate(value) if @strict
  @value = value
  @value_is_set = true
  @value
end

#set?Boolean

Returns:



231
232
233
# File 'lib/logstash/settings.rb', line 231

def set?
  @value_is_set
end

#strict?Boolean

Returns:



235
236
237
# File 'lib/logstash/settings.rb', line 235

def strict?
  @strict
end

#to_hashObject



251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/logstash/settings.rb', line 251

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_valueObject



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

def validate_value
  validate(value)
end

#valueObject



227
228
229
# File 'lib/logstash/settings.rb', line 227

def value
  @value_is_set ? @value : default
end