Class: Superstore::Associations::Builder::Association
- Inherits:
-
Object
- Object
- Superstore::Associations::Builder::Association
- Defined in:
- lib/superstore/associations/builder/association.rb
Instance Attribute Summary collapse
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #define_reader ⇒ Object
- #define_writer ⇒ Object
-
#initialize(model, name, options) ⇒ Association
constructor
A new instance of Association.
- #mixin ⇒ Object
Constructor Details
#initialize(model, name, options) ⇒ Association
Returns a new instance of Association.
8 9 10 |
# File 'lib/superstore/associations/builder/association.rb', line 8 def initialize(model, name, ) @model, @name, = model, name, end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
7 8 9 |
# File 'lib/superstore/associations/builder/association.rb', line 7 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/superstore/associations/builder/association.rb', line 7 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/superstore/associations/builder/association.rb', line 7 def end |
Class Method Details
.build(model, name, options) ⇒ Object
3 4 5 |
# File 'lib/superstore/associations/builder/association.rb', line 3 def self.build(model, name, ) new(model, name, ).build end |
Instance Method Details
#build ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/superstore/associations/builder/association.rb', line 12 def build define_writer define_reader reflection = Superstore::Associations::Reflection.new(macro, name, model, ) ActiveRecord::Reflection.add_reflection model, name, reflection end |
#define_reader ⇒ Object
31 32 33 34 35 36 |
# File 'lib/superstore/associations/builder/association.rb', line 31 def define_reader name = self.name mixin.redefine_method(name) do association(name).reader end end |
#define_writer ⇒ Object
24 25 26 27 28 29 |
# File 'lib/superstore/associations/builder/association.rb', line 24 def define_writer name = self.name mixin.redefine_method("#{name}=") do |records| association(name).writer(records) end end |
#mixin ⇒ Object
20 21 22 |
# File 'lib/superstore/associations/builder/association.rb', line 20 def mixin model.generated_association_methods end |