Class: MongoMapper::Plugins::Rails::ActiveRecordAssociationAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/mongo_mapper/plugins/rails/active_record_association_adapter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(association, macro) ⇒ ActiveRecordAssociationAdapter

Returns a new instance of ActiveRecordAssociationAdapter.



23
24
25
26
27
28
29
# File 'lib/mongo_mapper/plugins/rails/active_record_association_adapter.rb', line 23

def initialize(association, macro)
  @klass, @name = association.klass, association.name
  # only include compatible options
  @options = association.options.slice(:conditions, :order)

  @macro = macro
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



6
7
8
# File 'lib/mongo_mapper/plugins/rails/active_record_association_adapter.rb', line 6

def klass
  @klass
end

#macroObject (readonly)

Returns the value of attribute macro.



6
7
8
# File 'lib/mongo_mapper/plugins/rails/active_record_association_adapter.rb', line 6

def macro
  @macro
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/mongo_mapper/plugins/rails/active_record_association_adapter.rb', line 6

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/mongo_mapper/plugins/rails/active_record_association_adapter.rb', line 6

def options
  @options
end

Class Method Details

.for_association(association) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mongo_mapper/plugins/rails/active_record_association_adapter.rb', line 8

def self.for_association(association)
  macro = case association
  when MongoMapper::Plugins::Associations::BelongsToAssociation
    :belongs_to
  when MongoMapper::Plugins::Associations::ManyAssociation
    :has_many
  when MongoMapper::Plugins::Associations::OneAssociation
    :has_one
  else
    raise "no #{name} for association of type #{association.class}"
  end

  new(association, macro)
end