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/definition/error.rb,
lib/table_structure/schema/dsl/result_builder.rb,
lib/table_structure/schema/dsl/context_builder.rb,
lib/table_structure/schema/definition/validator.rb,
lib/table_structure/schema/dsl/column_converter.rb,
lib/table_structure/schema/dsl/column_definition.rb

Defined Under Namespace

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

Constant Summary collapse

DEFAULT_OPTIONS =
{ result_type: :array }.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

#column_converters ⇒ Object



41
42
43
# File 'lib/table_structure/schema.rb', line 41

def column_converters
  @table_structure_schema_table_.column_converters
end

#header(context: nil) ⇒ Object



31
32
33
34
# File 'lib/table_structure/schema.rb', line 31

def header(context: nil)
  context = self.class.context_builders[:header].call(context)
  @table_structure_schema_table_.header(context)
end

#initialize(context: nil, **options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/table_structure/schema.rb', line 15

def initialize(context: nil, **options)
  column_definitions = self.class.column_definitions
  column_converters = self.class.column_converters
  result_builders = self.class.result_builders
  context = self.class.context_builders[:table].call(context)
  options = DEFAULT_OPTIONS.merge(self.class.options).merge(options)
  @table_structure_schema_table_ =
    Table.new(
      column_definitions,
      column_converters,
      result_builders,
      context,
      options
    )
end

#result_builders ⇒ Object



45
46
47
# File 'lib/table_structure/schema.rb', line 45

def result_builders
  @table_structure_schema_table_.result_builders
end

#row(context: nil) ⇒ Object



36
37
38
39
# File 'lib/table_structure/schema.rb', line 36

def row(context: nil)
  context = self.class.context_builders[:row].call(context)
  @table_structure_schema_table_.row(context)
end