class XMigra::DeclarativeSupport::Table::Constraint

Constants

SUBTYPES

Attributes

name[RW]

Public Class Methods

bad_spec(message) click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 130
def self.bad_spec(message)
  raise SpecificationError, message
end
deserialize(name, constr_spec) click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 134
def self.deserialize(name, constr_spec)
  constraint_type = constr_spec['type'] || implicit_type(name) || bad_spec(
    "No type specified (or inferrable) for constraint #{name}"
  )
  constraint_type = Constraint.type_by_identifier(constraint_type) || bad_spec(
    %Q{Unknown constraint type "#{constraint_type}" for constraint #{name}}
  )
  
  constraint_type.new(name, constr_spec)
end
each_type(&blk) click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 122
def self.each_type(&blk)
  SUBTYPES.each(&blk)
end
implicit_type(name) click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 145
def self.implicit_type(name)
  return if name.nil?
  Constraint.each_type.find do |type|
    next unless type.const_defined?(:IMPLICIT_PREFIX)
    break type::IDENTIFIER if name.start_with?(type::IMPLICIT_PREFIX)
  end
end
inherited(subclass) click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 118
def self.inherited(subclass)
  SUBTYPES << subclass
end
new(name, constr_spec) click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 157
def initialize(name, constr_spec)
  @name = name
end
type_by_identifier(identifier) click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 126
def self.type_by_identifier(identifier)
  SUBTYPES.find {|t| t.const_defined?(:IDENTIFIER) && t::IDENTIFIER == identifier}
end

Public Instance Methods

constraint_type() click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 153
def constraint_type
  self.class::IDENTIFIER.gsub(' ', '_').to_sym
end
only_on_column_at_creation?() click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 163
def only_on_column_at_creation?
  false
end

Protected Instance Methods

creation_name_sql() click to toggle source
# File lib/xmigra/declarative_support/table.rb, line 168
def creation_name_sql
  return "" if name.nil?
  "CONSTRAINT #{name} "
end