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 a field reference of the form “[hello]” to the underlying store hash into => {“world” => “foo”}
Instance Method Summary collapse
-
#del(field_reference) ⇒ Object
The removed value in @store for this field reference.
-
#get(field_reference) ⇒ Object
The value in @store for this field reference.
-
#include?(field_reference) ⇒ Boolean
True if the store contains a value for this field reference.
-
#initialize(store) ⇒ Accessors
constructor
A new instance of Accessors.
-
#set(field_reference, value) ⇒ Object
The value set.
Constructor Details
#initialize(store) ⇒ Accessors
Returns a new instance of Accessors.
42 43 44 45 46 47 48 49 50 |
# File 'lib/logstash/util/accessors.rb', line 42 def initialize(store) @store = store # @lut is a lookup table between a field reference and a [target, key] tuple # where target is the containing Hash or Array for key in @store. # this allows us to directly access the containing object for key instead of # walking the field reference path into the inner @store objects @lut = {} end |
Instance Method Details
#del(field_reference) ⇒ Object
Returns the removed value in @store for this field reference.
70 71 72 73 74 |
# File 'lib/logstash/util/accessors.rb', line 70 def del(field_reference) target, key = lookup(field_reference) return nil unless target target.is_a?(Array) ? target.delete_at(key.to_i) : target.delete(key) end |
#get(field_reference) ⇒ Object
Returns the value in @store for this field reference.
54 55 56 57 58 |
# File 'lib/logstash/util/accessors.rb', line 54 def get(field_reference) target, key = lookup(field_reference) return nil unless target target.is_a?(Array) ? target[key.to_i] : target[key] end |
#include?(field_reference) ⇒ Boolean
Returns true if the store contains a value for this field reference.
78 79 80 81 82 83 |
# File 'lib/logstash/util/accessors.rb', line 78 def include?(field_reference) target, key = lookup(field_reference) return false unless target target.is_a?(Array) ? !target[key.to_i].nil? : target.include?(key) end |
#set(field_reference, value) ⇒ Object
Returns the value set.
63 64 65 66 |
# File 'lib/logstash/util/accessors.rb', line 63 def set(field_reference, value) target, key = lookup_or_create(field_reference) target[target.is_a?(Array) ? key.to_i : key] = value end |