Class: Torque::PostgreSQL::Adapter::OID::Enum

Inherits:
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Enum
  • Object
show all
Defined in:
lib/torque/postgresql/adapter/oid/enum.rb

Direct Known Subclasses

EnumSet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Enum

Returns a new instance of Enum.



22
23
24
25
26
27
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 22

def initialize(name)
  @name  = name
  @klass = Attributes::Enum.lookup(name)

  @enum_klass = self
end

Instance Attribute Details

#enum_klassObject (readonly)

Returns the value of attribute enum_klass.



7
8
9
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 7

def enum_klass
  @enum_klass
end

#klassObject (readonly)

Returns the value of attribute klass.



7
8
9
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 7

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 7

def name
  @name
end

#set_klassObject (readonly)

Returns the value of attribute set_klass.



7
8
9
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 7

def set_klass
  @set_klass
end

Class Method Details

.create(row, type_map) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 9

def self.create(row, type_map)
  name    = row['typname']
  oid     = row['oid'].to_i
  arr_oid = row['typarray'].to_i

  oid_klass     = Enum.new(name)
  oid_set_klass = EnumSet.new(name, oid_klass.klass)
  oid_klass.instance_variable_set(:@set_klass, oid_set_klass)

  type_map.register_type(oid,     oid_klass)
  type_map.register_type(arr_oid, oid_set_klass)
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
51
52
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 48

def ==(other)
  self.class == other.class &&
    other.klass == klass &&
    other.type == type
end

#assert_valid_value(value) ⇒ Object



39
40
41
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 39

def assert_valid_value(value)
  cast_value(value)
end

#hashObject



29
30
31
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 29

def hash
  [self.class, name].hash
end

#serialize(value) ⇒ Object



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

def serialize(value)
  return if value.blank?
  value = cast_value(value)
  value.to_s unless value.nil?
end

#type_cast_for_schema(value) ⇒ Object

Always use symbol value for schema dumper



44
45
46
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 44

def type_cast_for_schema(value)
  cast_value(value).to_sym.inspect
end