Module: TableStructure::Schema

Defined in:
lib/table_structure/schema.rb,
lib/table_structure/schema/table.rb,
lib/table_structure/schema/utils.rb,
lib/table_structure/schema/column.rb,
lib/table_structure/schema/definition.rb,
lib/table_structure/schema/dsl/option.rb,
lib/table_structure/schema/column/attrs.rb,
lib/table_structure/schema/column/schema.rb,
lib/table_structure/schema/definition/error.rb,
lib/table_structure/schema/dsl/result_builder.rb,
lib/table_structure/schema/definition/compiler.rb,
lib/table_structure/schema/dsl/context_builder.rb,
lib/table_structure/schema/table/key_decorator.rb,
lib/table_structure/schema/definition/validator.rb,
lib/table_structure/schema/dsl/column_converter.rb,
lib/table_structure/schema/dsl/column_definition.rb,
lib/table_structure/schema/table/context_builder.rb

Defined Under Namespace

Modules: Column, DSL, Utils Classes: Definition, Table

Constant Summary collapse

DEFAULT_OPTIONS =
{
  name_prefix: nil,
  name_suffix: nil,
  key_prefix: nil,
  key_suffix: nil
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/table_structure/schema.rb', line 5

def self.included(klass)
  klass.extend(DSL::ColumnConverter)
  klass.extend(DSL::ColumnDefinition)
  klass.extend(DSL::ContextBuilder)
  klass.extend(DSL::Option)
  klass.extend(DSL::ResultBuilder)
end

Instance Method Details

#create_table(result_type: :array, **options) ⇒ Object



38
39
40
41
# File 'lib/table_structure/schema.rb', line 38

def create_table(result_type: :array, **options)
  options = @table_structure_schema_definition_.options.merge(options)
  @table_structure_schema_definition_.create_table(result_type: result_type, **options)
end

#initialize(context: nil, name: self.class.name, **options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/table_structure/schema.rb', line 20

def initialize(context: nil, name: self.class.name, **options)
  column_definitions = [].concat(self.class.column_definitions)
  context_builders = {}.merge!(self.class.context_builders)
  column_converters = {}.merge!(self.class.column_converters)
  result_builders = {}.merge!(self.class.result_builders)
  options = DEFAULT_OPTIONS.merge(self.class.options).merge(options)
  @table_structure_schema_definition_ =
    Definition.new(
      name,
      column_definitions,
      context_builders,
      column_converters,
      result_builders,
      context,
      options
    )
end