Class: ActiveRecordInlineSchema::Config::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record_inline_schema/config/column.rb

Constant Summary collapse

DEFAULT_TYPE =
:string

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name, options) ⇒ Column

Returns a new instance of Column.



9
10
11
12
13
14
15
16
17
18
# File 'lib/active_record_inline_schema/config/column.rb', line 9

def initialize(parent, name, options)
  @parent = parent
  @name = name.to_s
  options = options.symbolize_keys
  if options.slice(:precision, :scale).keys.length == 1
    raise ::ArgumentError, %{[active_record_inline_schema] :precision and :scale must always be specified together}
  end
  @type = options.fetch(:type, DEFAULT_TYPE).to_sym
  @options = options.except :type, :name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/active_record_inline_schema/config/column.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/active_record_inline_schema/config/column.rb', line 7

def options
  @options
end

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/active_record_inline_schema/config/column.rb', line 4

def parent
  @parent
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/active_record_inline_schema/config/column.rb', line 6

def type
  @type
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/active_record_inline_schema/config/column.rb', line 28

def eql?(other)
  other.is_a?(self.class) and parent == other.parent and name == other.name and options == other.options
end

#hashObject



32
33
34
# File 'lib/active_record_inline_schema/config/column.rb', line 32

def hash
  [parent, name, options].hash
end

#inject(table_definition) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/active_record_inline_schema/config/column.rb', line 20

def inject(table_definition)
  if type != :primary_key and table_definition.respond_to?(type)
    table_definition.send type, name, options
  else
    table_definition.column name, type, options
  end
end