Class: Vedeu::Events::Trigger Private
- Inherits:
-
Object
- Object
- Vedeu::Events::Trigger
- Defined in:
- lib/vedeu/events/trigger.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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 ⇒ Array readonly protected private
- #name ⇒ Symbol|String readonly protected private
- #repository ⇒ Vedeu::Repositories::Repository readonly protected private
Class Method Summary collapse
-
.trigger(name, *args) ⇒ Array
private
Trigger an event by name.
Instance Method Summary collapse
-
#initialize(name, *args) ⇒ Vedeu::Events::Trigger
constructor
private
Returns a new instance of Vedeu::Events::Trigger.
-
#registered_events ⇒ Array|Array<Vedeu::Events::Event>
private
private
Return all of the registered events for this name.
- #results ⇒ Array<void>|void private private
-
#trigger ⇒ Array
private
Trigger the event and return the result or an array of results.
Constructor Details
#initialize(name, *args) ⇒ Vedeu::Events::Trigger
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Vedeu::Events::Trigger.
33 34 35 36 37 |
# File 'lib/vedeu/events/trigger.rb', line 33 def initialize(name, *args) @name = name @args = args @repository = Vedeu.events end |
Instance Attribute Details
#args ⇒ Array (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 |
# File 'lib/vedeu/events/trigger.rb', line 62 def args @args end |
#name ⇒ Symbol|String (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
58 59 60 |
# File 'lib/vedeu/events/trigger.rb', line 58 def name @name end |
#repository ⇒ Vedeu::Repositories::Repository (readonly, protected)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 |
# File 'lib/vedeu/events/trigger.rb', line 66 def repository @repository end |
Class Method Details
.trigger(name, *args) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Trigger an event by name.
23 24 25 |
# File 'lib/vedeu/events/trigger.rb', line 23 def self.trigger(name, *args) new(name, *args).trigger end |
Instance Method Details
#registered_events ⇒ Array|Array<Vedeu::Events::Event> (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return all of the registered events for this name.
78 79 80 81 82 83 84 85 86 |
# File 'lib/vedeu/events/trigger.rb', line 78 def registered_events return repository.find(name) if repository.registered?(name) Vedeu::Events::Aliases.find(name).map do |event_name| Vedeu::Events::Trigger.trigger(event_name, *args) end [] end |
#results ⇒ Array<void>|void (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
71 72 73 |
# File 'lib/vedeu/events/trigger.rb', line 71 def results @results ||= registered_events.map { |event| event.trigger(*args) } end |
#trigger ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Trigger the event and return the result or an array of results.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vedeu/events/trigger.rb', line 43 def trigger if results.empty? Vedeu.log(type: :event, message: "No action for: '#{name.inspect}'") end return results[0] if results.one? results end |