Module: TableStructure::Schema
- Defined in:
- lib/table_structure/schema.rb,
lib/table_structure/schema/utils.rb,
lib/table_structure/schema/row_builder.rb,
lib/table_structure/schema/class_methods.rb,
lib/table_structure/schema/key_converter.rb,
lib/table_structure/schema/columns/schema.rb,
lib/table_structure/schema/dsl/row_builder.rb,
lib/table_structure/schema/column_converter.rb,
lib/table_structure/schema/columns/attributes.rb,
lib/table_structure/schema/dsl/context_builder.rb,
lib/table_structure/schema/dsl/column_converter.rb,
lib/table_structure/schema/dsl/column_definition.rb,
lib/table_structure/schema/definition/row_builder.rb,
lib/table_structure/schema/definition/columns/error.rb,
lib/table_structure/schema/definition/context_builder.rb,
lib/table_structure/schema/definition/column_converter.rb,
lib/table_structure/schema/definition/columns/compiler.rb,
lib/table_structure/schema/definition/columns/validator.rb,
lib/table_structure/schema/definition/columns/attributes.rb,
lib/table_structure/schema/definition/columns/schema_class.rb,
lib/table_structure/schema/definition/columns/schema_instance.rb
Defined Under Namespace
Modules: ClassMethods, ColumnConverter, Columns, DSL, Definition, RowBuilder, Utils Classes: KeyConverter
Instance Attribute Summary collapse
-
#column_converters ⇒ Object
readonly
Returns the value of attribute column_converters.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#context_builders ⇒ Object
readonly
Returns the value of attribute context_builders.
-
#key_converter ⇒ Object
readonly
Returns the value of attribute key_converter.
-
#row_builders ⇒ Object
readonly
Returns the value of attribute row_builders.
Class Method Summary collapse
Instance Method Summary collapse
- #contain_callable?(attribute) ⇒ Boolean
- #initialize(name: self.class.name, context: nil, name_prefix: nil, name_suffix: nil, key_prefix: nil, key_suffix: nil, nil_definitions_ignored: false, &block) ⇒ Object
Instance Attribute Details
#column_converters ⇒ Object (readonly)
Returns the value of attribute column_converters.
23 24 25 |
# File 'lib/table_structure/schema.rb', line 23 def column_converters @column_converters end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
23 24 25 |
# File 'lib/table_structure/schema.rb', line 23 def columns @columns end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
23 24 25 |
# File 'lib/table_structure/schema.rb', line 23 def context @context end |
#context_builders ⇒ Object (readonly)
Returns the value of attribute context_builders.
23 24 25 |
# File 'lib/table_structure/schema.rb', line 23 def context_builders @context_builders end |
#key_converter ⇒ Object (readonly)
Returns the value of attribute key_converter.
23 24 25 |
# File 'lib/table_structure/schema.rb', line 23 def key_converter @key_converter end |
#row_builders ⇒ Object (readonly)
Returns the value of attribute row_builders.
23 24 25 |
# File 'lib/table_structure/schema.rb', line 23 def row_builders @row_builders end |
Class Method Details
.create_class(&block) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/table_structure/schema.rb', line 13 def self.create_class(&block) raise ::TableStructure::Error, 'No block given.' unless block schema_module = self Class.new do include schema_module class_eval(&block) end end |
.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::RowBuilder) klass.extend(ClassMethods) end |
Instance Method Details
#contain_callable?(attribute) ⇒ Boolean
88 89 90 |
# File 'lib/table_structure/schema.rb', line 88 def contain_callable?(attribute) @columns.any? { |column| column.contain_callable?(attribute) } end |
#initialize(name: self.class.name, context: nil, name_prefix: nil, name_suffix: nil, key_prefix: nil, key_suffix: nil, nil_definitions_ignored: false, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/table_structure/schema.rb', line 30 def initialize( name: self.class.name, context: nil, name_prefix: nil, name_suffix: nil, key_prefix: nil, key_suffix: nil, nil_definitions_ignored: false, &block ) schema_classes = [self.class] if block_given? schema_classes << ::TableStructure::Schema.create_class(&block) end @context_builders = schema_classes .map(&:context_builders) .reduce({}, &:merge!) table_context_builder = @context_builders.delete(:table) @context = table_context_builder ? table_context_builder.call(context) : context @column_converters = schema_classes .map(&:column_converters) .reduce({}, &:merge!) .merge( ColumnConverter.create_optional_converters( name_prefix: name_prefix, name_suffix: name_suffix ) ) @key_converter = KeyConverter.new( prefix: key_prefix, suffix: key_suffix ) @row_builders = RowBuilder.prepend_default_builders( schema_classes .map(&:row_builders) .reduce({}, &:merge!) ) @columns = Definition::Columns::Compiler .new( name, schema_classes.map(&:column_definitions).reduce([], &:concat), { nil_definitions_ignored: nil_definitions_ignored } ) .compile(@context) end |