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.
- #message ⇒ String private private
-
#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 each registered event for this name.
-
#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
#message ⇒ String (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 74 75 76 77 78 79 80 81 82 |
# File 'lib/vedeu/events/trigger.rb', line 71 def if args.size > 1 "Triggering: '#{name.inspect}' with #{args.inspect}" elsif args.one? "Triggering: '#{name.inspect}' for #{args.first.inspect}" else "Triggering: '#{name.inspect}'" end end |
#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.
102 103 104 105 106 107 108 109 110 |
# File 'lib/vedeu/events/trigger.rb', line 102 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.
Trigger each registered event for this name.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/vedeu/events/trigger.rb', line 87 def results @results ||= registered_events.map do |event| Vedeu.outdent do Vedeu.log(type: :event, message: ) Vedeu.indent do event.trigger(*args) end end end 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 Vedeu.config.debug? && results.empty? Vedeu.log(type: :nonevent, message: "No action for: '#{name.inspect}'") end return results[0] if results.one? results end |