Module: Announce::Subscriber
- Defined in:
- lib/announce/subscriber.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#delegate_event(event) ⇒ Object
For use in adapters to delegate to method named receive_subject_action.
- #delegate_method(message = @message) ⇒ Object
- #perform(*args) ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/announce/subscriber.rb', line 4 def self.included(base) base.class_eval do attr_accessor :subject, :action, :message end base.extend(ClassMethods) end |
Instance Method Details
#delegate_event(event) ⇒ Object
For use in adapters to delegate to method named receive_subject_action
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/announce/subscriber.rb', line 23 def delegate_event(event) = event.deep_symbolize_keys @subject = [:subject] @action = [:action] if [, subject, action].any? { |a| a.nil? } raise "Message, subject, and action are not all specified for '#{event.inspect}'" end if respond_to?(delegate_method) public_send(delegate_method, [:body]) else raise "`#{self.class.name}` is subscribed, but doesn't implement `#{delegate_method}` for '#{event.inspect}'" end end |
#delegate_method(message = @message) ⇒ Object
39 40 41 |
# File 'lib/announce/subscriber.rb', line 39 def delegate_method( = ) ['receive', [:subject], [:action]].join('_') end |
#perform(*args) ⇒ Object
18 19 20 |
# File 'lib/announce/subscriber.rb', line 18 def perform(*args) delegate_event(*args) end |