Module: Promiscuous::Subscriber::Model
- Extended by:
- ActiveSupport::Concern
- Includes:
- Envelope
- Included in:
- ActiveRecord
- Defined in:
- lib/promiscuous/subscriber/model.rb
Instance Method Summary collapse
- #destroy_instance ⇒ Object
- #fetch ⇒ Object
- #fetch_existing ⇒ Object
- #fetch_new ⇒ Object
- #process ⇒ Object
- #process_attributes? ⇒ Boolean
- #save_instance ⇒ Object
Instance Method Details
#destroy_instance ⇒ Object
54 55 56 |
# File 'lib/promiscuous/subscriber/model.rb', line 54 def destroy_instance instance.destroy end |
#fetch ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/promiscuous/subscriber/model.rb', line 29 def fetch case operation when :create then fetch_new when :update then fetch_existing when :destroy then fetch_existing end end |
#fetch_existing ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/promiscuous/subscriber/model.rb', line 13 def fetch_existing if foreign_key if klass.respond_to?("find_by_#{foreign_key}!") klass.__send__("find_by_#{foreign_key}!", id) elsif klass.respond_to?("find_by") klass.find_by(foreign_key => id) else record = klass.where(foreign_key => id).first raise self.class.missing_record_exception.new(klass, id) if record.nil? record end else klass.find(id) end end |
#fetch_new ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/promiscuous/subscriber/model.rb', line 5 def fetch_new if foreign_key klass.new(foreign_key => id) else klass.new.tap { |o| o.id = id } end end |
#process ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/promiscuous/subscriber/model.rb', line 41 def process super case operation when :create then save_instance when :update then save_instance when :destroy then destroy_instance end end |
#process_attributes? ⇒ Boolean
37 38 39 |
# File 'lib/promiscuous/subscriber/model.rb', line 37 def process_attributes? operation != :destroy end |
#save_instance ⇒ Object
50 51 52 |
# File 'lib/promiscuous/subscriber/model.rb', line 50 def save_instance instance.save! end |