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.



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

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



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

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

#serialize(value) ⇒ Object



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

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

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

#typeObject



14
15
16
# File 'lib/torque/postgresql/adapter/oid/enum_set.rb', line 14

def type
  :enum_set
end

#type_cast_for_schema(value) ⇒ Object

Always use symbol values for schema dumper



33
34
35
# File 'lib/torque/postgresql/adapter/oid/enum_set.rb', line 33

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