Sha256: 3ccbdbe75ed71a56944496750e84a072387acfdc1af66e97e3a389e0fae0885a

Contents?: true

Size: 855 Bytes

Versions: 7

Compression:

Stored size: 855 Bytes

Contents

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

7 entries across 7 versions & 1 rubygems

Version Path
ridgepole-0.8.0.rc1 lib/ridgepole/dsl_parser.rb
ridgepole-0.7.7 lib/ridgepole/dsl_parser.rb
ridgepole-0.7.6 lib/ridgepole/dsl_parser.rb
ridgepole-0.7.5 lib/ridgepole/dsl_parser.rb
ridgepole-0.7.5.beta3 lib/ridgepole/dsl_parser.rb
ridgepole-0.7.5.beta2 lib/ridgepole/dsl_parser.rb
ridgepole-0.7.5.beta lib/ridgepole/dsl_parser.rb