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.



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

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.



9
10
11
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 9

def enum_klass
  @enum_klass
end

#klassObject (readonly)

Returns the value of attribute klass.



9
10
11
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 9

def klass
  @klass
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 9

def name
  @name
end

#set_klassObject (readonly)

Returns the value of attribute set_klass.



9
10
11
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 9

def set_klass
  @set_klass
end

Class Method Details

.create(row, type_map) ⇒ Object



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

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



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

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

#assert_valid_value(value) ⇒ Object



41
42
43
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 41

def assert_valid_value(value)
  cast_value(value)
end

#hashObject



31
32
33
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 31

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

#serialize(value) ⇒ Object



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

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



46
47
48
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 46

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