Class: RailsAdmin::Adapters::Mongoid::AbstractObject

Inherits:
ActiveRecord::AbstractObject show all
Defined in:
lib/rails_admin/adapters/mongoid/abstract_object.rb

Instance Attribute Summary

Attributes inherited from ActiveRecord::AbstractObject

#object

Instance Method Summary collapse

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

#destroyObject



25
26
27
28
# File 'lib/rails_admin/adapters/mongoid/abstract_object.rb', line 25

def destroy
  object.destroy
  object
end