Class: Stealth::Flow::EventCollection
- Inherits:
-
Hash
- Object
- Hash
- Stealth::Flow::EventCollection
- Defined in:
- lib/stealth/flow/event_collection.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #first_applicable(name, object_context) ⇒ Object
- #flat ⇒ Object
- #include?(name_or_obj) ⇒ Boolean
- #push(name, event) ⇒ Object
Instance Method Details
#[](name) ⇒ Object
8 9 10 |
# File 'lib/stealth/flow/event_collection.rb', line 8 def [](name) super name.to_sym # Normalize to symbol end |
#first_applicable(name, object_context) ⇒ Object
33 34 35 36 37 |
# File 'lib/stealth/flow/event_collection.rb', line 33 def first_applicable(name, object_context) (self[name] || []).detect do |event| event.condition_applicable?(object_context) && event end end |
#flat ⇒ Object
18 19 20 21 22 |
# File 'lib/stealth/flow/event_collection.rb', line 18 def flat self.values.flatten.uniq do |event| [:name, :transitions_to, :meta, :action].map { |m| event.send(m) } end end |
#include?(name_or_obj) ⇒ Boolean
24 25 26 27 28 29 30 31 |
# File 'lib/stealth/flow/event_collection.rb', line 24 def include?(name_or_obj) case name_or_obj when Event flat.include? name_or_obj else !(self[name_or_obj].nil?) end end |
#push(name, event) ⇒ Object
12 13 14 15 16 |
# File 'lib/stealth/flow/event_collection.rb', line 12 def push(name, event) key = name.to_sym self[key] ||= [] self[key] << event end |