Class: Torque::PostgreSQL::Adapter::OID::EnumSet

Inherits:
Enum
  • Object
show all
Defined in:
lib/torque/postgresql/adapter/oid/enum_set.rb

Instance Attribute Summary

Attributes inherited from Enum

#enum_klass, #klass, #name, #set_klass

Instance Method Summary collapse

Methods inherited from Enum

#==, #assert_valid_value, create, #hash

Constructor Details

#initialize(name, enum_klass) ⇒ EnumSet

Returns a new instance of EnumSet.



8
9
10
11
12
13
14
# File 'lib/torque/postgresql/adapter/oid/enum_set.rb', line 8

def initialize(name, enum_klass)
  @name  = name + '[]'
  @klass = Attributes::EnumSet.lookup(name, enum_klass)

  @set_klass = self
  @enum_klass = enum_klass
end

Instance Method Details

#deserialize(value) ⇒ Object



20
21
22
23
24
# File 'lib/torque/postgresql/adapter/oid/enum_set.rb', line 20

def deserialize(value)
  return unless value.present?
  value = value[1..-2].split(',') if value.is_a?(String)
  cast_value(value)
end

#serialize(value) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/torque/postgresql/adapter/oid/enum_set.rb', line 26

def serialize(value)
  return if value.blank?
  value = cast_value(value)

  return if value.blank?
  "{#{value.map(&:to_s).join(',')}}"
end

#typeObject



16
17
18
# File 'lib/torque/postgresql/adapter/oid/enum_set.rb', line 16

def type
  :enum
end

#type_cast_for_schema(value) ⇒ Object

Always use symbol values for schema dumper



35
36
37
# File 'lib/torque/postgresql/adapter/oid/enum_set.rb', line 35

def type_cast_for_schema(value)
  cast_value(value).map(&:to_sym).inspect
end