Class: LogStash::Util::Accessors
- Inherits:
-
Object
- Object
- LogStash::Util::Accessors
- Defined in:
- lib/logstash/util/accessors.rb
Overview
Accessors uses a lookup table to speedup access of an accessor field of the type “[hello]” to the underlying store hash into => {“world” => “foo”}
Instance Method Summary collapse
- #del(accessor) ⇒ Object
- #get(accessor) ⇒ Object
- #include?(accessor) ⇒ Boolean
-
#initialize(store) ⇒ Accessors
constructor
A new instance of Accessors.
- #set(accessor, value) ⇒ Object
- #strict_set(accessor, value) ⇒ Object
Constructor Details
#initialize(store) ⇒ Accessors
Returns a new instance of Accessors.
28 29 30 31 |
# File 'lib/logstash/util/accessors.rb', line 28 def initialize(store) @store = store @lut = {} end |
Instance Method Details
#del(accessor) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/logstash/util/accessors.rb', line 49 def del(accessor) target, key = lookup(accessor) unless target.nil? target.is_a?(Array) ? target.delete_at(key.to_i) : target.delete(key) end end |
#get(accessor) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/logstash/util/accessors.rb', line 33 def get(accessor) target, key = lookup(accessor) unless target.nil? target.is_a?(Array) ? target[key.to_i] : target[key] end end |
#include?(accessor) ⇒ Boolean
56 57 58 59 60 |
# File 'lib/logstash/util/accessors.rb', line 56 def include?(accessor) target, key = lookup_path(accessor) return false unless target target.is_a?(Array) ? !target[key.to_i].nil? : target.include?(key) end |
#set(accessor, value) ⇒ Object
40 41 42 43 |
# File 'lib/logstash/util/accessors.rb', line 40 def set(accessor, value) target, key = store_and_lookup(accessor) target[target.is_a?(Array) ? key.to_i : key] = value end |
#strict_set(accessor, value) ⇒ Object
45 46 47 |
# File 'lib/logstash/util/accessors.rb', line 45 def strict_set(accessor, value) set(accessor, LogStash::Event.validate_value(value)) end |