module ActiveRecord::Postgres::Constraints::SchemaCreation

Public Instance Methods

adjust_nesting(nesting, token) click to toggle source
# File lib/active_record/postgres/constraints/schema_creation.rb, line 24
def adjust_nesting(nesting, token)
  nesting_was = nesting
  nesting += 1 if '(' == token
  nesting -= 1 if ')' == token
  [nesting, (1 == nesting_was && nesting.zero?)]
end
visit_TableDefinition(table_definition) click to toggle source

rubocop:disable Naming/MethodName

Calls superclass method
# File lib/active_record/postgres/constraints/schema_creation.rb, line 8
def visit_TableDefinition(table_definition)
  # rubocop:enable Naming/MethodName
  result = super
  return result unless table_definition.constraints

  nesting = 0
  # Find the closing paren of the "CREATE TABLE ( ... )" clause
  index = result.length.times do |i|
    token = result[i]
    nesting, should_break = adjust_nesting(nesting, token)
    break i if should_break
  end
  result[index] = ", #{table_definition.constraints.join(', ')})"
  result
end