Class: RailsAdmin::Adapters::Mongoid::AbstractObject
- Inherits:
-
ActiveRecord::AbstractObject
- Object
- ActiveRecord::AbstractObject
- RailsAdmin::Adapters::Mongoid::AbstractObject
- Defined in:
- lib/rails_admin/adapters/mongoid/abstract_object.rb
Instance Attribute Summary
Attributes inherited from ActiveRecord::AbstractObject
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(object) ⇒ AbstractObject
constructor
A new instance of AbstractObject.
Methods inherited from ActiveRecord::AbstractObject
#method_missing, #save, #set_attributes
Constructor Details
#initialize(object) ⇒ AbstractObject
Returns a new instance of AbstractObject.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rails_admin/adapters/mongoid/abstract_object.rb', line 6 def initialize(object) super object.associations.each do |name, association| if association.macro == :references_many instance_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{name.to_s.singularize}_ids #{name}.map{|item| item.id } end def #{name.to_s.singularize}_ids=(items) self.#{name} = items. map{|item_id| self.#{name}.klass.find(item_id) rescue nil }. compact end RUBY end end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RailsAdmin::Adapters::ActiveRecord::AbstractObject
Instance Method Details
#destroy ⇒ Object
25 26 27 28 |
# File 'lib/rails_admin/adapters/mongoid/abstract_object.rb', line 25 def destroy object.destroy object end |