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) ⇒ Object
Disables an event temporarily.
-
#disabled_events ⇒ Set
The set of disabled events.
-
#enable_event(event) ⇒ Object
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
113 114 115 |
# File 'lib/signals/subscriber.rb', line 113 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 args.one? ? args.first : args end |
#disable_event(event) ⇒ Object
Disables an event temporarily
77 78 79 80 |
# File 'lib/signals/subscriber.rb', line 77 def disable_event(event) disabled_events.add(event) self end |
#disabled_events ⇒ Set
The set of disabled events
119 120 121 |
# File 'lib/signals/subscriber.rb', line 119 def disabled_events @disabled_events ||= Set.new end |
#enable_event(event) ⇒ Object
Enables an event that was disabled
84 85 86 87 |
# File 'lib/signals/subscriber.rb', line 84 def enable_event(event) disabled_events.delete(event) self end |
#event?(event) ⇒ Boolean
Checks to see if the event is present
106 107 108 |
# File 'lib/signals/subscriber.rb', line 106 def event?(event) events.include?(event) end |
#event_disabled?(event) ⇒ Boolean
Checks to see if the event is disabled
92 93 94 |
# File 'lib/signals/subscriber.rb', line 92 def event_disabled?(event) disabled_events.include?(event) end |
#event_enabled?(event) ⇒ Boolean
Checks to see if the event is enabled
99 100 101 |
# File 'lib/signals/subscriber.rb', line 99 def event_enabled?(event) !event_disabled?(event) end |
#events ⇒ Hash
The hash of events that the subscriber is listening for
125 126 127 |
# File 'lib/signals/subscriber.rb', line 125 def events self.class.events.freeze end |