Class: MultipleMan::Subscribers::ModelSubscriber

Inherits:
Base
  • Object
show all
Defined in:
lib/multiple_man/subscribers/model_subscriber.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#klass

Instance Method Summary collapse

Methods inherited from Base

#listen_to, #routing_key

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, options)
  self.model_class = klass
  super(options[:to] || klass.name)
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/multiple_man/subscribers/model_subscriber.rb', line 10

def options
  @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, options[: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