Class: Superstore::Associations::Reflection
- Inherits:
-
Object
- Object
- Superstore::Associations::Reflection
- Defined in:
- lib/superstore/associations/reflection.rb
Instance Attribute Summary collapse
-
#macro ⇒ Object
readonly
Returns the value of attribute macro.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #association_class ⇒ Object
- #class_name ⇒ Object
- #default_primary_key? ⇒ Boolean
- #foreign_key ⇒ Object
-
#initialize(macro, name, model, options) ⇒ Reflection
constructor
A new instance of Reflection.
- #instance_variable_name ⇒ Object
- #polymorphic? ⇒ Boolean
- #polymorphic_column ⇒ Object
- #primary_key ⇒ Object
Constructor Details
#initialize(macro, name, model, options) ⇒ Reflection
Returns a new instance of Reflection.
5 6 7 8 9 10 |
# File 'lib/superstore/associations/reflection.rb', line 5 def initialize(macro, name, model, ) @macro = macro @name = name @model = model @options = end |
Instance Attribute Details
#macro ⇒ Object (readonly)
Returns the value of attribute macro.
4 5 6 |
# File 'lib/superstore/associations/reflection.rb', line 4 def macro @macro end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
4 5 6 |
# File 'lib/superstore/associations/reflection.rb', line 4 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/superstore/associations/reflection.rb', line 4 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/superstore/associations/reflection.rb', line 4 def @options end |
Instance Method Details
#association_class ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/superstore/associations/reflection.rb', line 12 def association_class case macro when :belongs_to Superstore::Associations::BelongsTo when :has_many Superstore::Associations::HasMany when :has_one Superstore::Associations::HasOne end end |
#class_name ⇒ Object
48 49 50 |
# File 'lib/superstore/associations/reflection.rb', line 48 def class_name @class_name ||= ([:class_name] || name.to_s.classify) end |
#default_primary_key? ⇒ Boolean
36 37 38 |
# File 'lib/superstore/associations/reflection.rb', line 36 def default_primary_key? primary_key == "id" end |
#foreign_key ⇒ Object
28 29 30 |
# File 'lib/superstore/associations/reflection.rb', line 28 def foreign_key @foreign_key ||= [:foreign_key] || derive_foreign_key end |
#instance_variable_name ⇒ Object
24 25 26 |
# File 'lib/superstore/associations/reflection.rb', line 24 def instance_variable_name "@#{name}" end |
#polymorphic? ⇒ Boolean
44 45 46 |
# File 'lib/superstore/associations/reflection.rb', line 44 def polymorphic? [:polymorphic] end |
#polymorphic_column ⇒ Object
40 41 42 |
# File 'lib/superstore/associations/reflection.rb', line 40 def polymorphic_column "#{name}_type" end |
#primary_key ⇒ Object
32 33 34 |
# File 'lib/superstore/associations/reflection.rb', line 32 def primary_key [:primary_key] || "id" end |