Class: MultipleMan::Subscribers::ModelSubscriber
- Defined in:
- lib/multiple_man/subscribers/model_subscriber.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Attributes inherited from Base
Instance Method Summary collapse
- #create(payload) ⇒ Object (also: #update, #seed)
- #destroy(payload) ⇒ Object
-
#initialize(klass, options) ⇒ ModelSubscriber
constructor
A new instance of ModelSubscriber.
Methods inherited from Base
Constructor Details
#initialize(klass, options) ⇒ ModelSubscriber
Returns a new instance of ModelSubscriber.
4 5 6 7 8 |
# File 'lib/multiple_man/subscribers/model_subscriber.rb', line 4 def initialize(klass, ) self.model_class = klass super([:to] || klass.name) self. = end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
10 11 12 |
# File 'lib/multiple_man/subscribers/model_subscriber.rb', line 10 def @options end |
Instance Method Details
#create(payload) ⇒ Object Also known as: update, seed
12 13 14 15 16 17 |
# File 'lib/multiple_man/subscribers/model_subscriber.rb', line 12 def create(payload) id = payload[:id] model = find_model(id) MultipleMan::ModelPopulator.new(model, [:fields]).populate(id: find_conditions(id), data: payload[:data]) model.save! end |
#destroy(payload) ⇒ Object
22 23 24 25 |
# File 'lib/multiple_man/subscribers/model_subscriber.rb', line 22 def destroy(payload) model = find_model(payload[:id]) model.destroy! end |