Class: Vedeu::Trigger
- Inherits:
-
Object
- Object
- Vedeu::Trigger
- Defined in:
- lib/vedeu/events/trigger.rb
Overview
Trigger a registered or system event by name with arguments. If the event stored returns a value, that is returned. If multiple events are registered for a name, then the result of each event will be returned as part of a collection.
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
private
Returns the value of attribute args.
-
#name ⇒ Object
readonly
private
Returns the value of attribute name.
-
#repository ⇒ Object
readonly
private
Returns the value of attribute repository.
Class Method Summary collapse
Instance Method Summary collapse
- #initialize(name, *args) ⇒ Trigger constructor
- #registered_events ⇒ Array|Array<Vedeu::Event> private
- #results ⇒ Array<void>|void private
- #trigger ⇒ Array
Constructor Details
#initialize(name, *args) ⇒ Trigger
23 24 25 26 27 |
# File 'lib/vedeu/events/trigger.rb', line 23 def initialize(name, *args) @name = name @args = args @repository = Vedeu.events end |
Instance Attribute Details
#args ⇒ Object (readonly, private)
Returns the value of attribute args.
43 44 45 |
# File 'lib/vedeu/events/trigger.rb', line 43 def args @args end |
#name ⇒ Object (readonly, private)
Returns the value of attribute name.
43 44 45 |
# File 'lib/vedeu/events/trigger.rb', line 43 def name @name end |
#repository ⇒ Object (readonly, private)
Returns the value of attribute repository.
43 44 45 |
# File 'lib/vedeu/events/trigger.rb', line 43 def repository @repository end |
Class Method Details
.trigger(name, *args) ⇒ Array
17 18 19 |
# File 'lib/vedeu/events/trigger.rb', line 17 def self.trigger(name, *args) new(name, *args).trigger end |
Instance Method Details
#registered_events ⇒ Array|Array<Vedeu::Event> (private)
53 54 55 56 57 |
# File 'lib/vedeu/events/trigger.rb', line 53 def registered_events return [] unless repository.registered?(name) repository.find(name) end |
#results ⇒ Array<void>|void (private)
48 49 50 |
# File 'lib/vedeu/events/trigger.rb', line 48 def results @results ||= registered_events.map { |event| event.trigger(*args) } end |
#trigger ⇒ Array
31 32 33 34 35 36 37 38 39 |
# File 'lib/vedeu/events/trigger.rb', line 31 def trigger if results.one? results.first else results end end |