module Flatter::Extensions::ActiveRecord
Public Instance Methods
apply(*)
click to toggle source
Calls superclass method
# File lib/flatter/extensions/active_record.rb, line 102 def apply(*) return super unless ar? !!::ActiveRecord::Base.transaction do super or raise ::ActiveRecord::Rollback end end
ar?(object = target)
click to toggle source
# File lib/flatter/extensions/active_record.rb, line 163 def ar?(object = target) object.class < ::ActiveRecord::Base end
assign_foreign_keys_for_mountings()
click to toggle source
# File lib/flatter/extensions/active_record.rb, line 147 def assign_foreign_keys_for_mountings associated_mountings(:foreign_key).each do |mounting| mounting.target[mounting.foreign_key] = target.id end end
assign_foreign_keys_from_mountings()
click to toggle source
# File lib/flatter/extensions/active_record.rb, line 140 def assign_foreign_keys_from_mountings associated_mountings(:mounter_foreign_key).each do |mounting| target[mounting.mounter_foreign_key] = mounting.target.id end end
associated_mountings(key)
click to toggle source
# File lib/flatter/extensions/active_record.rb, line 154 def associated_mountings(key) root_mountings.select do |mounting| mounter = mounting.mounter mounter = mounter.mounter if mounter.trait? mounting.options.key?(key) && mounter == self end end
build_collection_item()
click to toggle source
# File lib/flatter/extensions/active_record.rb, line 39 def build_collection_item return build_collection_item_without_ar unless mounter!.try(:ar?) mounter!.target.association(name.to_sym).try(:build) || build_collection_item_without_ar end
Also aliased as: build_collection_item_without_ar
delete_target_item(item)
click to toggle source
Calls superclass method
# File lib/flatter/extensions/active_record.rb, line 122 def delete_target_item(item) item.destroy! if ar?(item) super end
disable_ar_callbacks(*callbacks)
click to toggle source
# File lib/flatter/extensions/active_record.rb, line 94 def disable_ar_callbacks(*callbacks) self.enabled_ar_callbacks -= callbacks end
Also aliased as: disable_ar_callback
enable_ar_callbacks(*callbacks)
click to toggle source
# File lib/flatter/extensions/active_record.rb, line 89 def enable_ar_callbacks(*callbacks) self.enabled_ar_callbacks += callbacks enabled_ar_callbacks.uniq! end
Also aliased as: enable_ar_callback
save()
click to toggle source
Calls superclass method
# File lib/flatter/extensions/active_record.rb, line 110 def save !!::ActiveRecord::Base.transaction do begin @ar_error = nil super rescue ::ActiveRecord::StatementInvalid => e @ar_error = e raise ::ActiveRecord::Rollback end end end
save_target()
click to toggle source
Calls superclass method
# File lib/flatter/extensions/active_record.rb, line 127 def save_target return super unless ar? assign_foreign_keys_from_mountings result = target.save_with_callbacks(enabled_ar_callbacks) assign_foreign_keys_for_mountings if result result != false end