Class: StaticModel::Associations::Association
- Inherits:
-
Object
- Object
- StaticModel::Associations::Association
- Defined in:
- lib/static_model/associations.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#foreign_key ⇒ Object
readonly
Returns the value of attribute foreign_key.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #define_association_methods ⇒ Object
-
#initialize(klass, name, options = {}) ⇒ Association
constructor
A new instance of Association.
- #reflection_klass ⇒ Object
Constructor Details
#initialize(klass, name, options = {}) ⇒ Association
Returns a new instance of Association.
28 29 30 31 32 33 34 35 |
# File 'lib/static_model/associations.rb', line 28 def initialize(klass, name, = {}) @klass = klass @name = name @options = @reflection_klass_name = @options[:class_name] || @name.to_s.classify @foreign_key = @options[:foreign_key] define_association_methods end |
Instance Attribute Details
#foreign_key ⇒ Object (readonly)
Returns the value of attribute foreign_key.
26 27 28 |
# File 'lib/static_model/associations.rb', line 26 def foreign_key @foreign_key end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
26 27 28 |
# File 'lib/static_model/associations.rb', line 26 def klass @klass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
26 27 28 |
# File 'lib/static_model/associations.rb', line 26 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/static_model/associations.rb', line 26 def @options end |
Instance Method Details
#define_association_methods ⇒ Object
46 47 48 |
# File 'lib/static_model/associations.rb', line 46 def define_association_methods raise 'Should only use descendants of Association' end |
#reflection_klass ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/static_model/associations.rb', line 37 def reflection_klass Object.const_get(@reflection_klass_name) rescue eval <<-EOT class #{@reflection_klass_name}; end; #{@reflection_klass_name} EOT end |