Sha256: 295d7678bde8e7fd17e23ff2152538c1df14f6b5c3bde71bbdd17c9bcd6f543e

Contents?: true

Size: 886 Bytes

Versions: 4

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

module Ridgepole
  class DSLParser
    def initialize(options = {})
      @options = options
    end

    def parse(dsl, opts = {})
      definition, execute = Context.eval(dsl, opts)
      check_orphan_index(definition)
      check_orphan_foreign_key(definition)
      [definition, execute]
    end

    private

    def check_orphan_index(definition)
      definition.each do |table_name, attrs|
        raise "Table `#{table_name}` to create the index is not defined: #{attrs[:indices].keys.join(',')}" if attrs[:indices] && !(attrs[:definition])
      end
    end

    def check_orphan_foreign_key(definition)
      definition.each do |table_name, attrs|
        raise "Table `#{table_name}` to create the foreign key is not defined: #{attrs[:foreign_keys].keys.join(',')}" if attrs[:foreign_keys] && !(attrs[:definition])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ridgepole-0.8.3 lib/ridgepole/dsl_parser.rb
ridgepole-0.8.0 lib/ridgepole/dsl_parser.rb
ridgepole-0.8.0.rc2 lib/ridgepole/dsl_parser.rb
ridgepole-0.7.8 lib/ridgepole/dsl_parser.rb