Module: Signals::Subscriber::InstanceMethods
- Defined in:
- lib/signals/subscriber.rb
Instance Method Summary collapse
-
#actions_for(event) ⇒ Array
Get actions for a specific event.
-
#disable_event(event) ⇒ void
Disables an event temporarily.
-
#disabled_events ⇒ Set
The set of disabled events.
-
#enable_event(event) ⇒ void
Enables an event that was disabled.
-
#event?(event) ⇒ Boolean
Checks to see if the event is present.
-
#event_disabled?(event) ⇒ Boolean
Checks to see if the event is disabled.
-
#event_enabled?(event) ⇒ Boolean
Checks to see if the event is enabled.
-
#events ⇒ Hash
The hash of events that the subscriber is listening for.
- #execute_event(event, *args) ⇒ Object
Instance Method Details
#actions_for(event) ⇒ Array
Get actions for a specific event
110 111 112 |
# File 'lib/signals/subscriber.rb', line 110 def actions_for(event) self.events[event] || Array.new end |
#disable_event(event) ⇒ void
This method returns an undefined value.
Disables an event temporarily
73 74 75 76 |
# File 'lib/signals/subscriber.rb', line 73 def disable_event(event) disabled_events.add(event) nil end |
#disabled_events ⇒ Set
The set of disabled events
116 117 118 |
# File 'lib/signals/subscriber.rb', line 116 def disabled_events @disabled_events ||= Set.new end |
#enable_event(event) ⇒ void
This method returns an undefined value.
Enables an event that was disabled
81 82 83 84 |
# File 'lib/signals/subscriber.rb', line 81 def enable_event(event) disabled_events.delete(event) nil end |
#event?(event) ⇒ Boolean
Checks to see if the event is present
103 104 105 |
# File 'lib/signals/subscriber.rb', line 103 def event?(event) events.include?(event) end |
#event_disabled?(event) ⇒ Boolean
Checks to see if the event is disabled
89 90 91 |
# File 'lib/signals/subscriber.rb', line 89 def event_disabled?(event) disabled_events.include?(event) end |
#event_enabled?(event) ⇒ Boolean
Checks to see if the event is enabled
96 97 98 |
# File 'lib/signals/subscriber.rb', line 96 def event_enabled?(event) !event_disabled?(event) end |
#events ⇒ Hash
The hash of events that the subscriber is listening for
122 123 124 |
# File 'lib/signals/subscriber.rb', line 122 def events self.class.events.freeze end |
#execute_event(event, *args) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/signals/subscriber.rb', line 62 def execute_event(event, *args) if event_enabled?(event) actions_for(event).each do |action| self.send(action, *args) if self.respond_to?(action) end end end |