Module: Signals::Subscriber::InstanceMethods
- Defined in:
- lib/signals/subscriber.rb
Instance Method Summary collapse
-
#actions_for(event) ⇒ Array
Get actions for a specific event.
- #call(event, *args) ⇒ void
-
#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.
Instance Method Details
#actions_for(event) ⇒ Array
Get actions for a specific event
115 116 117 |
# File 'lib/signals/subscriber.rb', line 115 def actions_for(event) self.events[event] || Array.new end |
#call(event, *args) ⇒ void
This method returns an undefined value.
66 67 68 69 70 71 72 73 |
# File 'lib/signals/subscriber.rb', line 66 def call(event, *args) if event_enabled?(event) actions_for(event).each do |action| self.send(action, *args) if self.respond_to?(action) end end nil end |
#disable_event(event) ⇒ void
This method returns an undefined value.
Disables an event temporarily
78 79 80 81 |
# File 'lib/signals/subscriber.rb', line 78 def disable_event(event) disabled_events.add(event) nil end |
#disabled_events ⇒ Set
The set of disabled events
121 122 123 |
# File 'lib/signals/subscriber.rb', line 121 def disabled_events @disabled_events ||= Set.new end |
#enable_event(event) ⇒ void
This method returns an undefined value.
Enables an event that was disabled
86 87 88 89 |
# File 'lib/signals/subscriber.rb', line 86 def enable_event(event) disabled_events.delete(event) nil end |
#event?(event) ⇒ Boolean
Checks to see if the event is present
108 109 110 |
# File 'lib/signals/subscriber.rb', line 108 def event?(event) events.include?(event) end |
#event_disabled?(event) ⇒ Boolean
Checks to see if the event is disabled
94 95 96 |
# File 'lib/signals/subscriber.rb', line 94 def event_disabled?(event) disabled_events.include?(event) end |
#event_enabled?(event) ⇒ Boolean
Checks to see if the event is enabled
101 102 103 |
# File 'lib/signals/subscriber.rb', line 101 def event_enabled?(event) !event_disabled?(event) end |
#events ⇒ Hash
The hash of events that the subscriber is listening for
127 128 129 |
# File 'lib/signals/subscriber.rb', line 127 def events self.class.events.freeze end |