Class: EventPeople::Listeners::Base
- Inherits:
-
Object
- Object
- EventPeople::Listeners::Base
- Defined in:
- lib/event_people/listeners/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #callback(method_name, event) ⇒ Object
- #fail! ⇒ Object
-
#initialize(context) ⇒ Base
constructor
A new instance of Base.
- #reject! ⇒ Object
- #success! ⇒ Object
Constructor Details
#initialize(context) ⇒ Base
Returns a new instance of Base.
4 5 6 |
# File 'lib/event_people/listeners/base.rb', line 4 def initialize(context) @context = context end |
Class Method Details
.bind(method, event_name) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/event_people/listeners/base.rb', line 24 def self.bind(method, event_name) app_name = ENV['RABBIT_EVENT_PEOPLE_APP_NAME'].downcase splitted_event_name = event_name.split('.') if splitted_event_name.size <= 3 Manager.register_listener_configuration( { listener_class: self, method: method, routing_key: fixed_event_name(event_name, 'all') } ) Manager.register_listener_configuration( { listener_class: self, method: method, routing_key: fixed_event_name(event_name, app_name) } ) else Manager.register_listener_configuration( { listener_class: self, method: method, routing_key: fixed_event_name(event_name, app_name) } ) end end |
.fixed_event_name(event_name, postfix) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/event_people/listeners/base.rb', line 54 def self.fixed_event_name(event_name, postfix) case event_name&.split('.')&.size when 4 parts = event_name.split('.') "#{parts[0..2].join('.')}.#{postfix}" when nil event_name else "#{event_name}.#{postfix}" end end |
Instance Method Details
#callback(method_name, event) ⇒ Object
8 9 10 |
# File 'lib/event_people/listeners/base.rb', line 8 def callback(method_name, event) send method_name, event end |
#fail! ⇒ Object
16 17 18 |
# File 'lib/event_people/listeners/base.rb', line 16 def fail! @context.fail! end |
#reject! ⇒ Object
20 21 22 |
# File 'lib/event_people/listeners/base.rb', line 20 def reject! @context.reject! end |
#success! ⇒ Object
12 13 14 |
# File 'lib/event_people/listeners/base.rb', line 12 def success! @context.success! end |