class Vorpal::Dsl::ConfigBuilder
Public Class Methods
new(clazz, options, db_driver)
click to toggle source
@private
# File lib/vorpal/dsl/config_builder.rb, line 12 def initialize(clazz, options, db_driver) @domain_class = clazz @class_options = options @has_manys = [] @has_ones = [] @belongs_tos = [] @attributes = [] @defaults_generator = DefaultsGenerator.new(clazz, db_driver) end
Public Instance Methods
attributes(*attributes)
click to toggle source
@private
# File lib/vorpal/dsl/config_builder.rb, line 23 def attributes(*attributes) @attributes.concat(attributes) end
attributes_with_id()
click to toggle source
@private
# File lib/vorpal/dsl/config_builder.rb, line 53 def attributes_with_id [:id].concat @attributes end
belongs_to(name, options={})
click to toggle source
@private
# File lib/vorpal/dsl/config_builder.rb, line 38 def belongs_to(name, options={}) @belongs_tos << build_belongs_to({name: name}.merge(options)) end
build()
click to toggle source
@private
# File lib/vorpal/dsl/config_builder.rb, line 43 def build class_config = build_class_config class_config.has_manys = @has_manys class_config.has_ones = @has_ones class_config.belongs_tos = @belongs_tos class_config end
has_many(name, options={})
click to toggle source
@private
# File lib/vorpal/dsl/config_builder.rb, line 28 def has_many(name, options={}) @has_manys << build_has_many({name: name}.merge(options)) end
has_one(name, options={})
click to toggle source
@private
# File lib/vorpal/dsl/config_builder.rb, line 33 def has_one(name, options={}) @has_ones << build_has_one({name: name}.merge(options)) end
Private Instance Methods
build_belongs_to(options)
click to toggle source
# File lib/vorpal/dsl/config_builder.rb, line 85 def build_belongs_to(options) associated_classes = options[:associated_classes] || options[:child_classes] || options[:associated_class] || options[:child_class] || @defaults_generator.associated_class(options[:name]) options[:associated_classes] = Array(associated_classes) options[:fk] ||= @defaults_generator.foreign_key(options[:name]) options[:unique_key_name] ||= (options[:primary_key] || "id") options[:owned] = options.fetch(:owned, true) Vorpal::Config::BelongsToConfig.new(options) end
build_class_config()
click to toggle source
# File lib/vorpal/dsl/config_builder.rb, line 59 def build_class_config Vorpal::Config::ClassConfig.new( domain_class: @domain_class, db_class: @class_options[:to] || @defaults_generator.build_db_class(@class_options[:table_name]), serializer: @class_options[:serializer] || @defaults_generator.serializer(attributes_with_id), deserializer: @class_options[:deserializer] || @defaults_generator.deserializer(attributes_with_id), primary_key_type: @class_options[:primary_key_type] || @class_options[:id] || :serial, ) end
build_has_many(options)
click to toggle source
# File lib/vorpal/dsl/config_builder.rb, line 69 def build_has_many(options) options[:associated_class] ||= options[:child_class] || @defaults_generator.associated_class(options[:name]) options[:fk] ||= @defaults_generator.foreign_key(@domain_class.name) options[:unique_key_name] ||= (options[:primary_key] || "id") options[:owned] = options.fetch(:owned, true) Vorpal::Config::HasManyConfig.new(options) end
build_has_one(options)
click to toggle source
# File lib/vorpal/dsl/config_builder.rb, line 77 def build_has_one(options) options[:associated_class] ||= options[:child_class] || @defaults_generator.associated_class(options[:name]) options[:fk] ||= @defaults_generator.foreign_key(@domain_class.name) options[:unique_key_name] ||= (options[:primary_key] || "id") options[:owned] = options.fetch(:owned, true) Vorpal::Config::HasOneConfig.new(options) end