Class: Bhf::Mongoid::Document::Reflection

Inherits:
Object
  • Object
show all
Defined in:
lib/bhf/mongoid/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mongoid_field) ⇒ Reflection

Returns a new instance of Reflection.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/bhf/mongoid/document.rb', line 20

def initialize(mongoid_field)
  @name = mongoid_field.name
  @klass = mongoid_field.class_name.constantize
  @foreign_key = mongoid_field.key
  @macro = case mongoid_field.macro
    when :references_and_referenced_in_many
      :has_and_belongs_to_many
    when :references_many
      :has_many
    when :references_one
      :has_one
    when :referenced_in
      :belongs_to
    else
      mongoid_field.macro
  end
end

Instance Attribute Details

#foreign_keyObject (readonly)

Returns the value of attribute foreign_key.



18
19
20
# File 'lib/bhf/mongoid/document.rb', line 18

def foreign_key
  @foreign_key
end

#klassObject (readonly)

Returns the value of attribute klass.



18
19
20
# File 'lib/bhf/mongoid/document.rb', line 18

def klass
  @klass
end

#macroObject (readonly)

Returns the value of attribute macro.



18
19
20
# File 'lib/bhf/mongoid/document.rb', line 18

def macro
  @macro
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/bhf/mongoid/document.rb', line 18

def name
  @name
end