Class: MR::Model::Association
- Inherits:
-
Object
- Object
- MR::Model::Association
- Defined in:
- lib/mr/model/associations.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#reader_method_name ⇒ Object
readonly
Returns the value of attribute reader_method_name.
-
#writer_method_name ⇒ Object
readonly
Returns the value of attribute writer_method_name.
Instance Method Summary collapse
- #define_accessor_on(model_class) ⇒ Object
-
#initialize(name) ⇒ Association
constructor
A new instance of Association.
Constructor Details
#initialize(name) ⇒ Association
Returns a new instance of Association.
90 91 92 93 94 95 96 |
# File 'lib/mr/model/associations.rb', line 90 def initialize(name) @name = name.to_s @reader_method_name = @name @writer_method_name = "#{@name}=" @association_reader_name = @name @association_writer_name = "#{@name}=" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
87 88 89 |
# File 'lib/mr/model/associations.rb', line 87 def name @name end |
#reader_method_name ⇒ Object (readonly)
Returns the value of attribute reader_method_name.
88 89 90 |
# File 'lib/mr/model/associations.rb', line 88 def reader_method_name @reader_method_name end |
#writer_method_name ⇒ Object (readonly)
Returns the value of attribute writer_method_name.
88 89 90 |
# File 'lib/mr/model/associations.rb', line 88 def writer_method_name @writer_method_name end |
Instance Method Details
#define_accessor_on(model_class) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/mr/model/associations.rb', line 98 def define_accessor_on(model_class) association = self model_class.class_eval do define_method(association.reader_method_name) do association.read(record) end define_method(association.writer_method_name) do |value| begin association.write(value, self, record){ |m| m.record } rescue BadAssociationValueError => exception raise ArgumentError, exception., caller end end end end |