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.



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

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



161
162
163
# File 'lib/xmigra/declarative_support/table.rb', line 161

def name
  @name
end

Class Method Details

.bad_spec(message) ⇒ Object

Raises:



130
131
132
# File 'lib/xmigra/declarative_support/table.rb', line 130

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

.deserialize(name, constr_spec) ⇒ Object



134
135
136
137
138
139
140
141
142
143
# 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) ⇒ Object



122
123
124
# File 'lib/xmigra/declarative_support/table.rb', line 122

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

.implicit_type(name) ⇒ Object



145
146
147
148
149
150
151
# 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) ⇒ Object



118
119
120
# File 'lib/xmigra/declarative_support/table.rb', line 118

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

.type_by_identifier(identifier) ⇒ Object



126
127
128
# 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

Instance Method Details

#constraint_typeObject



153
154
155
# File 'lib/xmigra/declarative_support/table.rb', line 153

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

#only_on_column_at_creation?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/xmigra/declarative_support/table.rb', line 163

def only_on_column_at_creation?
  false
end