Class: XMigra::DeclarativeSupport::Table::Column

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

Constant Summary collapse

SPEC_ATTRS =
[:name, :type]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(col_spec) ⇒ Column

Returns a new instance of Column.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/xmigra/declarative_support/table.rb', line 75

def initialize(col_spec)
  @primary_key = !!col_spec['primary key']
  @nullable = !!col_spec.fetch('nullable', true)
  SPEC_ATTRS.each do |a|
    instance_variable_set("@#{a}".to_sym, col_spec[a.to_s])
  end
  if default = col_spec['default']
    @default_constraint = DefaultConstraint.new(
      "DF_#{name}",
      StructureReader.new({
        'column'=>name,
        'value'=>default
      })
    )
  end
end

Instance Attribute Details

#default_constraintObject

Returns the value of attribute default_constraint.



93
94
95
# File 'lib/xmigra/declarative_support/table.rb', line 93

def default_constraint
  @default_constraint
end

Instance Method Details

#nullable=(value) ⇒ Object



105
106
107
# File 'lib/xmigra/declarative_support/table.rb', line 105

def nullable=(value)
  @nullable = value
end

#nullable?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/xmigra/declarative_support/table.rb', line 102

def nullable?
  @nullable
end

#primary_key=(value) ⇒ Object



98
99
100
# File 'lib/xmigra/declarative_support/table.rb', line 98

def primary_key=(value)
  @primary_key = value
end

#primary_key?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/xmigra/declarative_support/table.rb', line 95

def primary_key?
  @primary_key
end