Class: Workflow::EventCollection

Inherits:
Hash
  • Object
show all
Defined in:
lib/workflow/event_collection.rb

Instance Method Summary collapse

Instance Method Details

#[](name) ⇒ Object



4
5
6
# File 'lib/workflow/event_collection.rb', line 4

def [](name)
  super name.to_sym # Normalize to symbol
end

#first_applicable(name, object_context) ⇒ Object



29
30
31
32
33
# File 'lib/workflow/event_collection.rb', line 29

def first_applicable(name, object_context)
  (self[name] || []).detect do |event|
    event.condition_applicable?(object_context) && event
  end
end

#flatObject



14
15
16
17
18
# File 'lib/workflow/event_collection.rb', line 14

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

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
# File 'lib/workflow/event_collection.rb', line 20

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



8
9
10
11
12
# File 'lib/workflow/event_collection.rb', line 8

def push(name, event)
  key = name.to_sym
  self[key] ||= []
  self[key] << event
end