Class: TableStructure::Schema::Definition::Compiler
- Inherits:
-
Object
- Object
- TableStructure::Schema::Definition::Compiler
- Defined in:
- lib/table_structure/schema/definition/compiler.rb
Constant Summary collapse
- DEFAULT_ATTRS =
{ name: nil, key: nil, value: nil, size: nil, omitted: false }.freeze
- DEFAULT_SIZE =
1
Instance Method Summary collapse
- #compile(context = nil) ⇒ Object
-
#initialize(name, definitions, options) ⇒ Compiler
constructor
A new instance of Compiler.
Constructor Details
#initialize(name, definitions, options) ⇒ Compiler
Returns a new instance of Compiler.
17 18 19 20 21 |
# File 'lib/table_structure/schema/definition/compiler.rb', line 17 def initialize(name, definitions, ) @name = name @definitions = definitions = end |
Instance Method Details
#compile(context = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/table_structure/schema/definition/compiler.rb', line 23 def compile(context = nil) @definitions .map { |definition| Utils.evaluate_callable(definition, context) } .map.with_index do |definition, i| validator = Validator.new(@name, i, ) [definition] .flatten .map do |definition| if definition.is_a?(Hash) definition = DEFAULT_ATTRS.merge(definition) omitted = definition.delete(:omitted) next if Utils.evaluate_callable(omitted, context) validator.validate(definition) definition[:size] = determine_size(definition) definition elsif Utils.schema_instance?(definition) definition elsif Utils.schema_class?(definition) definition.new(context: context) else raise Error.new('Invalid definition.', @name, i) end end end .flatten .compact end |