Class: Torque::PostgreSQL::Adapter::OID::Enum
- Inherits:
-
ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Enum
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Enum
- Torque::PostgreSQL::Adapter::OID::Enum
- Defined in:
- lib/torque/postgresql/adapter/oid/enum.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#enum_klass ⇒ Object
readonly
Returns the value of attribute enum_klass.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#set_klass ⇒ Object
readonly
Returns the value of attribute set_klass.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #assert_valid_value(value) ⇒ Object
- #hash ⇒ Object
-
#initialize(name) ⇒ Enum
constructor
A new instance of Enum.
- #serialize(value) ⇒ Object
-
#type_cast_for_schema(value) ⇒ Object
Always use symbol value for schema dumper.
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_klass ⇒ Object (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 |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
9 10 11 |
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 9 def klass @klass end |
#name ⇒ Object (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_klass ⇒ Object (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 |
#hash ⇒ Object
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 |