lib/ridgepole/dsl_parser/context.rb in ridgepole-0.7.8 vs lib/ridgepole/dsl_parser/context.rb in ridgepole-0.8.0.rc1

- old
+ new

@@ -1,7 +1,5 @@ -# frozen_string_literal: true - module Ridgepole class DSLParser class Context attr_reader :__definition attr_reader :__execute @@ -26,11 +24,11 @@ def create_table(table_name, options = {}) table_name = table_name.to_s table_definition = TableDefinition.new(table_name, self) - options[:primary_key] = options[:primary_key].to_s if options[:primary_key]&.is_a?(Symbol) + options[:primary_key] = options[:primary_key].to_s if options[:primary_key] && options[:primary_key].is_a?(Symbol) if options[:id] && TableDefinition::ALIAS_TYPES.key?(options[:id]) type, type_default_opts = TableDefinition::ALIAS_TYPES[options[:id]] options[:id] = type options = type_default_opts.merge(options) end @@ -80,21 +78,21 @@ options[:name] = options[:name].to_s if options[:name] options[:primary_key] = options[:primary_key].to_s if options[:primary_key] options[:column] = options[:column].to_s if options[:column] @__definition[from_table] ||= {} @__definition[from_table][:foreign_keys] ||= {} - idx = options[:name] || [from_table, to_table, options[:column]] + idx = options[:name] || [from_table, to_table] raise "Foreign Key `#{from_table}(#{idx})` already defined" if @__definition[from_table][:foreign_keys][idx] @__definition[from_table][:foreign_keys][idx] = { to_table: to_table, options: options, } end def require(file) - schemafile = %r{\A/}.match?(file) ? file : File.join(@__working_dir, file) + schemafile = file =~ %r{\A/} ? file : File.join(@__working_dir, file) if File.exist?(schemafile) instance_eval(File.read(schemafile), schemafile) elsif File.exist?(schemafile + '.rb') instance_eval(File.read(schemafile + '.rb'), schemafile + '.rb')