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, ExistingFilePath, Integer, NullableString, Numeric, Port, PortRange, PositiveInteger, String, TimeValue, Validator, WritableDirectory

Instance Attribute Summary collapse

Instance Method Summary collapse

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.



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/logstash/settings.rb', line 143

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.



141
142
143
# File 'lib/logstash/settings.rb', line 141

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



141
142
143
# File 'lib/logstash/settings.rb', line 141

def name
  @name
end

Instance Method Details

#==(other) ⇒ Object



197
198
199
# File 'lib/logstash/settings.rb', line 197

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

#resetObject



177
178
179
180
# File 'lib/logstash/settings.rb', line 177

def reset
  @value = nil
  @value_is_set = false
end

#set(value) ⇒ Object



170
171
172
173
174
175
# File 'lib/logstash/settings.rb', line 170

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

#set?Boolean

Returns:



162
163
164
# File 'lib/logstash/settings.rb', line 162

def set?
  @value_is_set
end

#strict?Boolean

Returns:



166
167
168
# File 'lib/logstash/settings.rb', line 166

def strict?
  @strict
end

#to_hashObject



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/logstash/settings.rb', line 182

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



201
202
203
# File 'lib/logstash/settings.rb', line 201

def validate_value
  validate(value)
end

#valueObject



158
159
160
# File 'lib/logstash/settings.rb', line 158

def value
  @value_is_set ? @value : default
end