Class: MetaDb::Column

Inherits:
DbObject show all
Defined in:
lib/meta_db/db_object.rb

Instance Attribute Summary collapse

Attributes inherited from DbObject

#children, #name, #parent

Instance Method Summary collapse

Methods inherited from DbObject

#[], attrs, #dot, #dump, #dump_attrs, init, #inspect, #path

Constructor Details

#initialize(table, ordinal, name, type, default, is_identity, is_generated, is_nullable, is_updatable) ⇒ Column

Returns a new instance of Column.



247
248
249
250
251
# File 'lib/meta_db/db_object.rb', line 247

def initialize(table, ordinal, name, type, default, is_identity, is_generated, is_nullable, is_updatable)
  super(table, name)
  @type, @ordinal, @default, @is_identity, @is_generated, @is_nullable, @is_updatable =
      type, ordinal, default, is_identity, is_generated, is_nullable, is_updatable
end

Instance Attribute Details

#defaultObject (readonly)

Default value



226
227
228
# File 'lib/meta_db/db_object.rb', line 226

def default
  @default
end

#ordinalObject (readonly)

Ordinal number of the column



220
221
222
# File 'lib/meta_db/db_object.rb', line 220

def ordinal
  @ordinal
end

#typeObject (readonly)

Type of the column



223
224
225
# File 'lib/meta_db/db_object.rb', line 223

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object

Compare columns by table and ordinal



254
255
256
257
258
259
260
# File 'lib/meta_db/db_object.rb', line 254

def <=>(other)
  if other.is_a?(Column) && table == other.table
    ordinal <=> other.ordinal
  else
    super
  end
end

#generated?Boolean

True if column is auto generated

Returns:

  • (Boolean)


232
# File 'lib/meta_db/db_object.rb', line 232

def generated?() @is_generated end

#identity?Boolean

True if column is an identity column

Returns:

  • (Boolean)


229
# File 'lib/meta_db/db_object.rb', line 229

def identity?() @is_identity end

#nullable?Boolean

True if column is nullable

Returns:

  • (Boolean)


235
# File 'lib/meta_db/db_object.rb', line 235

def nullable?() @is_nullable end

#primary_key?Boolean

True if column is the single primary key of the table. Always false for tables with multiple primary keys

Returns:

  • (Boolean)


242
# File 'lib/meta_db/db_object.rb', line 242

def primary_key?() table.table? && self == table.primary_key_column end

#primary_key_column?Boolean

True is column is (part of) the primary key of the table

Returns:

  • (Boolean)


245
# File 'lib/meta_db/db_object.rb', line 245

def primary_key_column?() table.table? && table.primary_key_columns.include?(self) end

#updatable?Boolean

True if column is updatable

Returns:

  • (Boolean)


238
# File 'lib/meta_db/db_object.rb', line 238

def updatable?() @is_updatable end