Class: Vorpal::Dsl::ConfigBuilder
- Inherits:
-
Object
- Object
- Vorpal::Dsl::ConfigBuilder
- Defined in:
- lib/vorpal/dsl/config_builder.rb
Instance Method Summary collapse
-
#attributes(*attributes) ⇒ Object
Maps the given attributes to and from the domain object and the DB.
- #attributes_with_id ⇒ Object
-
#belongs_to(name, options = {}) ⇒ Object
Defines a one-to-one association with another type where the foreign key is stored on the parent.
- #build ⇒ Object
-
#has_many(name, options = {}) ⇒ Object
Defines a one-to-many association to another type where the foreign key is stored on the child.
-
#has_one(name, options = {}) ⇒ Object
Defines a one-to-one association to another type where the foreign key is stored on the child.
-
#initialize(clazz, options, db_driver) ⇒ ConfigBuilder
constructor
A new instance of ConfigBuilder.
Constructor Details
#initialize(clazz, options, db_driver) ⇒ ConfigBuilder
Returns a new instance of ConfigBuilder.
9 10 11 12 13 14 15 16 17 |
# File 'lib/vorpal/dsl/config_builder.rb', line 9 def initialize(clazz, , db_driver) @domain_class = clazz @class_options = @has_manys = [] @has_ones = [] @belongs_tos = [] @attributes = [] @defaults_generator = DefaultsGenerator.new(clazz, db_driver) end |
Instance Method Details
#attributes(*attributes) ⇒ Object
Maps the given attributes to and from the domain object and the DB. Not needed if a serializer and deserializer were provided.
21 22 23 |
# File 'lib/vorpal/dsl/config_builder.rb', line 21 def attributes(*attributes) @attributes.concat(attributes) end |
#attributes_with_id ⇒ Object
92 93 94 |
# File 'lib/vorpal/dsl/config_builder.rb', line 92 def attributes_with_id [:id].concat @attributes end |
#belongs_to(name, options = {}) ⇒ Object
Defines a one-to-one association with another type where the foreign key is stored on the parent.
This association can be polymorphic. I.E. children can be of different types.
In Object-Oriented programming, associations are directed. This means that they can only be traversed in one direction: from the type that defines the association (the one with the getter) to the type that is associated. They end that defines the association is called the ‘Parent’ and the end that is associated is called the ‘Child’.
77 78 79 |
# File 'lib/vorpal/dsl/config_builder.rb', line 77 def belongs_to(name, ={}) @belongs_tos << {name: name}.merge() end |
#build ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/vorpal/dsl/config_builder.rb', line 82 def build class_config = build_class_config class_config.has_manys = build_has_manys class_config.has_ones = build_has_ones class_config.belongs_tos = build_belongs_tos class_config end |
#has_many(name, options = {}) ⇒ Object
Defines a one-to-many association to another type where the foreign key is stored on the child.
In Object-Oriented programming, associations are directed. This means that they can only be traversed in one direction: from the type that defines the association (the one with the getter) to the type that is associated. They end that defines the association is called the ‘Parent’ and the end that is associated is called the ‘Child’.
38 39 40 |
# File 'lib/vorpal/dsl/config_builder.rb', line 38 def has_many(name, ={}) @has_manys << {name: name}.merge() end |
#has_one(name, options = {}) ⇒ Object
Defines a one-to-one association to another type where the foreign key is stored on the child.
In Object-Oriented programming, associations are directed. This means that they can only be traversed in one direction: from the type that defines the association (the one with the getter) to the type that is associated. They end that defines the association is called the ‘Parent’ and the end that is associated is called the ‘Child’.
56 57 58 |
# File 'lib/vorpal/dsl/config_builder.rb', line 56 def has_one(name, ={}) @has_ones << {name: name}.merge() end |