Module: ActiveRecord::Mysql::Enum::EnumColumnAdapter

Defined in:
lib/active_record/mysql/enum/enum_column_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.value_to_symbol(value) ⇒ Object

Safely convert the value to a symbol.



46
47
48
49
50
51
52
53
# File 'lib/active_record/mysql/enum/enum_column_adapter.rb', line 46

def value_to_symbol(value)
  case value
  when Symbol
    value
  when String
    value.to_sym if value.present?
  end
end

Instance Method Details

#initialize(*args, **kwargs, &block) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/active_record/mysql/enum/enum_column_adapter.rb', line 25

def initialize(*args, **kwargs, &block)
  super

  if type == :enum
    @default = if @default.present?
                 @default.to_sym
               end
  end
end

#type_cast_from_database(value) ⇒ Object

Convert to a symbol.



36
37
38
39
40
41
42
# File 'lib/active_record/mysql/enum/enum_column_adapter.rb', line 36

def type_cast_from_database(value)
  if type == :enum
    EnumColumnAdapter.value_to_symbol(value)
  else
    super
  end
end