Class: ActiveRecord::ConnectionAdapters::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_enum/activerecord_enum_pre42.rb

Instance Method Summary collapse

Instance Method Details

#enum?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/activerecord_enum/activerecord_enum_pre42.rb', line 41

def enum?
  type == :enum
end

#extract_default_with_enum(default) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/activerecord_enum/activerecord_enum_pre42.rb', line 29

def extract_default_with_enum default
  if type == :set
    default.split "," if default.present?
  else
    extract_default default
  end
end

#extract_limit_with_enum(field_type) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/activerecord_enum/activerecord_enum_pre42.rb', line 21

def extract_limit_with_enum field_type
  if field_type =~ /(?:enum|set)\(([^)]+)\)/i
    $1.scan( /'([^']*)'/ ).flatten
  else
    extract_limit field_type
  end
end

#initialize_with_enum(name, default, sql_type = nil, *args) ⇒ Object Also known as: initialize



4
5
6
7
8
9
# File 'lib/activerecord_enum/activerecord_enum_pre42.rb', line 4

def initialize_with_enum name, default, sql_type=nil, *args
  initialize_without_enum name, default, sql_type, *args
  @type = simplified_type_with_enum sql_type
  @limit = extract_limit_with_enum sql_type
  @default = extract_default_with_enum default
end

#set?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/activerecord_enum/activerecord_enum_pre42.rb', line 37

def set?
  type == :set
end

#simplified_type_with_enum(field_type) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/activerecord_enum/activerecord_enum_pre42.rb', line 13

def simplified_type_with_enum field_type
  if field_type =~ /enum|set/i
    $&.to_sym
  else
    simplified_type field_type
  end
end