Class: SampleModels::Model::Association
- Inherits:
-
Delegator
- Object
- Delegator
- SampleModels::Model::Association
- Defined in:
- lib/sample_models/model.rb
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #belongs_to? ⇒ Boolean
- #foreign_key ⇒ Object
- #foreign_type ⇒ Object
- #has_many? ⇒ Boolean
-
#initialize(assoc) ⇒ Association
constructor
A new instance of Association.
- #polymorphic? ⇒ Boolean
Constructor Details
#initialize(assoc) ⇒ Association
Returns a new instance of Association.
56 57 58 |
# File 'lib/sample_models/model.rb', line 56 def initialize(assoc) @assoc = assoc end |
Instance Method Details
#__getobj__ ⇒ Object
60 61 62 |
# File 'lib/sample_models/model.rb', line 60 def __getobj__ @assoc end |
#belongs_to? ⇒ Boolean
64 65 66 |
# File 'lib/sample_models/model.rb', line 64 def belongs_to? @assoc.macro == :belongs_to end |
#foreign_key ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/sample_models/model.rb', line 68 def foreign_key if @assoc.respond_to?(:foreign_key) @assoc.foreign_key else @assoc.primary_key_name end end |
#foreign_type ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/sample_models/model.rb', line 76 def foreign_type if @assoc.respond_to?(:foreign_type) @assoc.foreign_type else @assoc.instance_variable_get(:@options)[:foreign_type] end end |
#has_many? ⇒ Boolean
84 85 86 |
# File 'lib/sample_models/model.rb', line 84 def has_many? @assoc.macro == :has_many end |
#polymorphic? ⇒ Boolean
88 89 90 |
# File 'lib/sample_models/model.rb', line 88 def polymorphic? @assoc.[:polymorphic] end |