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.
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_klass ⇒ Object (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 |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
7 8 9 |
# File 'lib/torque/postgresql/adapter/oid/enum.rb', line 7 def klass @klass end |
#name ⇒ Object (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_klass ⇒ Object (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 |
#hash ⇒ Object
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 |