class TableStructure::Schema::Definition::Columns::Compiler
Public Class Methods
new( schema_name, definitions, nil_definitions_ignored: false )
click to toggle source
# File lib/table_structure/schema/definition/columns/compiler.rb, line 8 def initialize( schema_name, definitions, nil_definitions_ignored: false ) @schema_name = schema_name @definitions = definitions @nil_definitions_ignored = !!nil_definitions_ignored end
Public Instance Methods
compile(context = nil)
click to toggle source
# File lib/table_structure/schema/definition/columns/compiler.rb, line 18 def compile(context = nil) @definitions .map { |definition| Utils.evaluate_callable(definition, context) } .map.with_index do |definitions, i| validator = Validator.new(@schema_name, i) [definitions] .flatten .map do |definition| if definition.is_a?(Hash) Attributes.new(**definition, validator: validator) elsif Utils.schema_instance?(definition) SchemaInstance.new(definition) elsif Utils.schema_class?(definition) SchemaClass.new(definition) elsif definition.nil? && @nil_definitions_ignored next else raise Error.new('Invalid definition.', @schema_name, i) end end end .flatten .compact .reject { |column| column.omitted?(context: context) } .map { |column| column.compile(context: context) } end