Class: MultipleMan::ModelSubscriber
- Inherits:
-
Object
- Object
- MultipleMan::ModelSubscriber
- Defined in:
- lib/multiple_man/model_subscriber.rb
Class Attribute Summary collapse
-
.subscriptions ⇒ Object
Returns the value of attribute subscriptions.
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Class Method Summary collapse
Instance Method Summary collapse
- #create(payload) ⇒ Object (also: #update)
- #destroy(payload) ⇒ Object
-
#initialize(klass) ⇒ ModelSubscriber
constructor
A new instance of ModelSubscriber.
- #queue_name ⇒ Object
- #routing_key ⇒ Object
Constructor Details
#initialize(klass) ⇒ ModelSubscriber
Returns a new instance of ModelSubscriber.
13 14 15 |
# File 'lib/multiple_man/model_subscriber.rb', line 13 def initialize(klass) self.klass = klass end |
Class Attribute Details
.subscriptions ⇒ Object
Returns the value of attribute subscriptions.
6 7 8 |
# File 'lib/multiple_man/model_subscriber.rb', line 6 def subscriptions @subscriptions end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
17 18 19 |
# File 'lib/multiple_man/model_subscriber.rb', line 17 def klass @klass end |
Class Method Details
.register(klass) ⇒ Object
8 9 10 |
# File 'lib/multiple_man/model_subscriber.rb', line 8 def register(klass) self.subscriptions << new(klass) end |
Instance Method Details
#create(payload) ⇒ Object Also known as: update
19 20 21 22 23 |
# File 'lib/multiple_man/model_subscriber.rb', line 19 def create(payload) model = find_model(payload[:id]) model.attributes = payload[:data] model.save! end |
#destroy(payload) ⇒ Object
27 28 29 30 |
# File 'lib/multiple_man/model_subscriber.rb', line 27 def destroy(payload) model = find_model(payload[:id]) model.destroy! end |
#queue_name ⇒ Object
36 37 38 |
# File 'lib/multiple_man/model_subscriber.rb', line 36 def queue_name "#{MultipleMan.configuration.topic_name}.#{MultipleMan.configuration.app_name}.#{klass.name}" end |
#routing_key ⇒ Object
32 33 34 |
# File 'lib/multiple_man/model_subscriber.rb', line 32 def routing_key RoutingKey.new(klass).to_s end |