Class: XMigra::DeclarativeSupport::Table::Constraint

Inherits:
Object
  • Object
show all
Defined in:
lib/xmigra/declarative_support/table.rb

Constant Summary collapse

SUBTYPES =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, constr_spec) ⇒ Constraint

Returns a new instance of Constraint.



151
152
153
# File 'lib/xmigra/declarative_support/table.rb', line 151

def initialize(name, constr_spec)
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



155
156
157
# File 'lib/xmigra/declarative_support/table.rb', line 155

def name
  @name
end

Class Method Details

.bad_spec(message) ⇒ Object

Raises:



124
125
126
# File 'lib/xmigra/declarative_support/table.rb', line 124

def self.bad_spec(message)
  raise SpecificationError, message
end

.deserialize(name, constr_spec) ⇒ Object



128
129
130
131
132
133
134
135
136
137
# File 'lib/xmigra/declarative_support/table.rb', line 128

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) ⇒ Object



116
117
118
# File 'lib/xmigra/declarative_support/table.rb', line 116

def self.each_type(&blk)
  SUBTYPES.each(&blk)
end

.implicit_type(name) ⇒ Object



139
140
141
142
143
144
145
# File 'lib/xmigra/declarative_support/table.rb', line 139

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) ⇒ Object



112
113
114
# File 'lib/xmigra/declarative_support/table.rb', line 112

def self.inherited(subclass)
  SUBTYPES << subclass
end

.type_by_identifier(identifier) ⇒ Object



120
121
122
# File 'lib/xmigra/declarative_support/table.rb', line 120

def self.type_by_identifier(identifier)
  SUBTYPES.find {|t| t.const_defined?(:IDENTIFIER) && t::IDENTIFIER == identifier}
end

Instance Method Details

#constraint_typeObject



147
148
149
# File 'lib/xmigra/declarative_support/table.rb', line 147

def constraint_type
  self.class::IDENTIFIER.gsub(' ', '_').to_sym
end

#only_on_column_at_creation?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/xmigra/declarative_support/table.rb', line 157

def only_on_column_at_creation?
  false
end