Class: Automigration::DbColumn

Inherits:
Struct
  • Object
show all
Defined in:
lib/automigration/db_column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name_, type_, options_) ⇒ DbColumn

Returns a new instance of DbColumn.



3
4
5
6
# File 'lib/automigration/db_column.rb', line 3

def initialize(name_, type_, options_)
  super
  options_.assert_valid_keys(:default, :null, :limit, :scale, :precision)
end

Instance Attribute Details

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



2
3
4
# File 'lib/automigration/db_column.rb', line 2

def name
  @name
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



2
3
4
# File 'lib/automigration/db_column.rb', line 2

def options
  @options
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



2
3
4
# File 'lib/automigration/db_column.rb', line 2

def type
  @type
end

Class Method Details

.from_activerecord_column(column) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/automigration/db_column.rb', line 8

def self.from_activerecord_column(column)
  out = DbColumn.new(column.name.to_sym, column.type.to_sym, {
    :default => column.default,
    :null => column.null,
    :limit => column.limit,
    :scale => column.scale,
    :precision => column.precision
  })
end

Instance Method Details

#the_same?(other) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/automigration/db_column.rb', line 18

def the_same?(other)
  (__to_array <=> other.send(:__to_array)) == 0
end

#to_optionsObject



22
23
24
# File 'lib/automigration/db_column.rb', line 22

def to_options
  options.reject{|k, v| k != :default && v.nil?}
end