Class: Dbee::DslSchemaBuilder
- Inherits:
-
Object
- Object
- Dbee::DslSchemaBuilder
- Defined in:
- lib/dbee/dsl_schema_builder.rb
Overview
Builds a Dbee::Schema given a Dbee::Base (DSL) model. Note that this class does not exist in the “Dsl” module as it is not used for defining the DSL itself.
Instance Attribute Summary collapse
-
#dsl_model ⇒ Object
readonly
:nodoc:.
-
#key_chain ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#initialize(dsl_model, key_chain) ⇒ DslSchemaBuilder
constructor
A new instance of DslSchemaBuilder.
- #to_schema ⇒ Object
Constructor Details
#initialize(dsl_model, key_chain) ⇒ DslSchemaBuilder
Returns a new instance of DslSchemaBuilder.
17 18 19 20 21 22 |
# File 'lib/dbee/dsl_schema_builder.rb', line 17 def initialize(dsl_model, key_chain) @dsl_model = dsl_model || ArgumentError('dsl_model is required') @key_chain = key_chain || ArgumentError('key_chain is required') freeze end |
Instance Attribute Details
#dsl_model ⇒ Object (readonly)
:nodoc:
15 16 17 |
# File 'lib/dbee/dsl_schema_builder.rb', line 15 def dsl_model @dsl_model end |
#key_chain ⇒ Object (readonly)
:nodoc:
15 16 17 |
# File 'lib/dbee/dsl_schema_builder.rb', line 15 def key_chain @key_chain end |
Instance Method Details
#to_schema ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dbee/dsl_schema_builder.rb', line 24 def to_schema schema_spec = { dsl_model.inflected_class_name => model_config(dsl_model) } ancestor_paths(key_chain).each do |key_path| start_model = dsl_model key_path.ancestor_names.each do |association_name| start_model = append_model_and_relationship(schema_spec, start_model, association_name) end end Schema.new(schema_spec) end |