Module: VirtualAttributes::Base::Casts::ClassMethods

Defined in:
lib/virtual-attributes/base/casts.rb

Instance Method Summary collapse

Instance Method Details

#column(name, type, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
# File 'lib/virtual-attributes/base/casts.rb', line 16

def column(name, type, options = {})
  raise ArgumentError unless type.to_sym.in? TYPES

  super(name, options)

  self.columns[name.to_sym][:type]   = type.to_sym,
  self.columns[name.to_sym][:castor] =
    ActiveRecord::Type.const_get(type.to_s.classify)
                      .new(options.symbolize_keys
                                  .slice(:precision, :scale, :limit))
end