Class: Sus::Filter::Index
- Inherits:
-
Object
- Object
- Sus::Filter::Index
- Defined in:
- lib/sus/filter.rb
Instance Attribute Summary collapse
-
#contexts ⇒ Object
readonly
Returns the value of attribute contexts.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #add(parent) ⇒ Object
-
#initialize ⇒ Index
constructor
A new instance of Index.
- #insert(identity, context) ⇒ Object
Constructor Details
#initialize ⇒ Index
Returns a new instance of Index.
16 17 18 |
# File 'lib/sus/filter.rb', line 16 def initialize @contexts = {} end |
Instance Attribute Details
#contexts ⇒ Object (readonly)
Returns the value of attribute contexts.
20 21 22 |
# File 'lib/sus/filter.rb', line 20 def contexts @contexts end |
Instance Method Details
#[](key) ⇒ Object
39 40 41 |
# File 'lib/sus/filter.rb', line 39 def [] key @contexts[key] end |
#add(parent) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/sus/filter.rb', line 22 def add(parent) parent.children&.each do |identity, child| insert(identity, child) add(child) end end |
#insert(identity, context) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/sus/filter.rb', line 29 def insert(identity, context) key = identity.key if existing_context = @contexts[key] raise KeyError, "Assigning context to existing key: #{key.inspect}!" else @contexts[key] = context end end |