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.



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

def initialize(mongoid_field)
  @name = mongoid_field.name
  @klass = mongoid_field.class_name.constantize
  @foreign_key = mongoid_field.key
  @macro = mongoid_field.class.name.demodulize.underscore.to_sym
  # @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.



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

def foreign_key
  @foreign_key
end

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

#macroObject (readonly)

Returns the value of attribute macro.



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

def macro
  @macro
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end