Class: CassandraObject::BelongsTo::Builder
- Inherits:
-
Object
- Object
- CassandraObject::BelongsTo::Builder
- Defined in:
- lib/cassandra_object/belongs_to/builder.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) ⇒ Builder
constructor
A new instance of Builder.
- #mixin ⇒ Object
Constructor Details
#initialize(model, name, options) ⇒ Builder
Returns a new instance of Builder.
9 10 11 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 9 def initialize(model, name, ) @model, @name, @options = model, name, end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 8 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 8 def @options end |
Class Method Details
.build(model, name, options) ⇒ Object
4 5 6 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 4 def self.build(model, name, ) new(model, name, ).build end |
Instance Method Details
#build ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 13 def build define_writer define_reader reflection = CassandraObject::BelongsTo::Reflection.new(model, name, ) model.belongs_to_reflections = model.belongs_to_reflections.merge(name => reflection) end |
#define_reader ⇒ Object
32 33 34 35 36 37 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 32 def define_reader name = self.name mixin.redefine_method(name) do belongs_to_association(name).reader end end |
#define_writer ⇒ Object
25 26 27 28 29 30 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 25 def define_writer name = self.name mixin.redefine_method("#{name}=") do |records| belongs_to_association(name).writer(records) end end |
#mixin ⇒ Object
21 22 23 |
# File 'lib/cassandra_object/belongs_to/builder.rb', line 21 def mixin model.generated_belongs_to_methods end |