Class: XMigra::DeclarativeSupport::Table::DefaultConstraint

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

Constant Summary collapse

IDENTIFIER =
'default'
IMPLICIT_PREFIX =
'DF_'

Constants inherited from Constraint

Constraint::SUBTYPES

Instance Attribute Summary collapse

Attributes inherited from Constraint

#name

Instance Method Summary collapse

Methods inherited from Constraint

bad_spec, #constraint_type, deserialize, each_type, implicit_type, inherited, type_by_identifier

Constructor Details

#initialize(name, constr_spec) ⇒ DefaultConstraint

Returns a new instance of DefaultConstraint.



296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/xmigra/declarative_support/table.rb', line 296

def initialize(name, constr_spec)
  super(name, constr_spec)
  implicit_column = (
    name[IMPLICIT_PREFIX.length..-1] if name.start_with?(IMPLICIT_PREFIX)
  )
  @column = constr_spec['column'] || implicit_column || Constraint.bad_spec(
    %Q{Default constraint #{name} does not specify a "column"}
  )
  @expression = constr_spec['value'] || Constraint.bad_spec(
    %Q{Default constraint #{name} does not specify an expression to use as a "value"}
  )
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



309
310
311
# File 'lib/xmigra/declarative_support/table.rb', line 309

def column
  @column
end

#expressionObject

Returns the value of attribute expression.



309
310
311
# File 'lib/xmigra/declarative_support/table.rb', line 309

def expression
  @expression
end

Instance Method Details

#creation_sqlObject



315
316
317
# File 'lib/xmigra/declarative_support/table.rb', line 315

def creation_sql
  creation_name_sql + "DEFAULT #{expression} FOR #{column}"
end

#only_on_column_at_creation?Boolean

Returns:

  • (Boolean)


311
312
313
# File 'lib/xmigra/declarative_support/table.rb', line 311

def only_on_column_at_creation?
  true
end