Class: Maitredee::Subscriber::SubscriberProxy
- Inherits:
-
Object
- Object
- Maitredee::Subscriber::SubscriberProxy
- Defined in:
- lib/maitredee/subscriber.rb
Instance Attribute Summary collapse
-
#subscriber ⇒ Object
readonly
Returns the value of attribute subscriber.
Instance Method Summary collapse
-
#default_event(to:) ⇒ Object
configure a default method to be called if not specifically configured to be listened to.
-
#event(event_name, to: nil) ⇒ Object
configure subscriber to listen to event_name.
-
#initialize(subscriber) ⇒ SubscriberProxy
constructor
A new instance of SubscriberProxy.
Constructor Details
#initialize(subscriber) ⇒ SubscriberProxy
Returns a new instance of SubscriberProxy.
52 53 54 |
# File 'lib/maitredee/subscriber.rb', line 52 def initialize(subscriber) @subscriber = subscriber end |
Instance Attribute Details
#subscriber ⇒ Object (readonly)
Returns the value of attribute subscriber.
50 51 52 |
# File 'lib/maitredee/subscriber.rb', line 50 def subscriber @subscriber end |
Instance Method Details
#default_event(to:) ⇒ Object
configure a default method to be called if not specifically configured to be listened to
79 80 81 82 83 84 |
# File 'lib/maitredee/subscriber.rb', line 79 def default_event(to:) subscriber.event_configs.default = EventConfig.new( event_name: nil, action: to.to_s ) end |
#event(event_name, to: nil) ⇒ Object
configure subscriber to listen to event_name
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/maitredee/subscriber.rb', line 59 def event(event_name, to: nil) if event_name.nil? && to.nil? raise ArgumentError, "event_name and to: cannot both be nil" end if event_name.present? && /[@$"]/ =~ event_name.to_sym.inspect && to.nil? raise ArgumentError, "'#{event_name}' is not a valid method name, you must set the 'to' parameter" end event_config = EventConfig.new( event_name: event_name.to_s, action: (to || event_name).to_s ) subscriber.event_configs[event_config.event_name] = event_config end |