Class: Migsupo::Schema::ColumnDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/migsupo/schema/column_definition.rb

Constant Summary collapse

COMPARABLE_OPTIONS =
%i[null default limit precision scale comment].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, options: {}) ⇒ ColumnDefinition

Returns a new instance of ColumnDefinition.



8
9
10
11
12
13
# File 'lib/migsupo/schema/column_definition.rb', line 8

def initialize(name:, type:, options: {})
  @name    = name.to_s
  @type    = type.to_sym
  @options = normalize_options(options)
  freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/migsupo/schema/column_definition.rb', line 4

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/migsupo/schema/column_definition.rb', line 4

def options
  @options
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/migsupo/schema/column_definition.rb', line 4

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



15
16
17
18
19
# File 'lib/migsupo/schema/column_definition.rb', line 15

def ==(other)
  return false unless other.is_a?(ColumnDefinition)

  name == other.name && type == other.type && comparable_options == other.comparable_options
end

#comparable_optionsObject



31
32
33
# File 'lib/migsupo/schema/column_definition.rb', line 31

def comparable_options
  options.slice(*COMPARABLE_OPTIONS).reject { |_, v| v.nil? }
end

#hashObject



23
24
25
# File 'lib/migsupo/schema/column_definition.rb', line 23

def hash
  [name, type, comparable_options].hash
end

#to_hObject



27
28
29
# File 'lib/migsupo/schema/column_definition.rb', line 27

def to_h
  { name: name, type: type, options: options }
end