lib/ridgepole/dsl_parser/context.rb in ridgepole-0.8.0.rc1 vs lib/ridgepole/dsl_parser/context.rb in ridgepole-0.8.0.rc2
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module Ridgepole
class DSLParser
class Context
attr_reader :__definition
attr_reader :__execute
@@ -24,11 +26,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] && options[:primary_key].is_a?(Symbol)
+ options[:primary_key] = options[:primary_key].to_s if 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
@@ -78,21 +80,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]
+ idx = options[:name] || [from_table, to_table, options[:column]]
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 = file =~ %r{\A/} ? file : File.join(@__working_dir, file)
+ schemafile = %r{\A/}.match?(file) ? 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')