Class: TableStructure::Schema::Definition
- Inherits:
-
Object
- Object
- TableStructure::Schema::Definition
- Defined in:
- lib/table_structure/schema/definition.rb,
lib/table_structure/schema/definition/error.rb,
lib/table_structure/schema/definition/validator.rb
Defined Under Namespace
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) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(name, definitions, options) ⇒ Definition
Returns a new instance of Definition.
16 17 18 19 20 |
# File 'lib/table_structure/schema/definition.rb', line 16 def initialize(name, definitions, ) @name = name @definitions = definitions = end |
Instance Method Details
#compile(context = nil) ⇒ Object
22 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 |
# File 'lib/table_structure/schema/definition.rb', line 22 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 |