Class: ActsAsHavingStringId::StringId::Type
- Inherits:
-
ActiveRecord::Type::Value
- Object
- ActiveRecord::Type::Value
- ActsAsHavingStringId::StringId::Type
- Defined in:
- lib/acts_as_having_string_id/string_id.rb
Instance Method Summary collapse
- #cast(value) ⇒ Object
- #deserialize(value) ⇒ Object
-
#initialize(klass) ⇒ Type
constructor
A new instance of Type.
- #serialize(value) ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(klass) ⇒ Type
Returns a new instance of Type.
43 44 45 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 43 def initialize(klass) @klass = klass end |
Instance Method Details
#cast(value) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 51 def cast(value) if value == nil nil else ActsAsHavingStringId::StringId(@klass, value) end end |
#deserialize(value) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 59 def deserialize(value) if value.is_a?(String) || value.is_a?(Fixnum) ActsAsHavingStringId::StringId(@klass, value) elsif value == nil nil else super end end |
#serialize(value) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 69 def serialize(value) if value == nil nil else ActsAsHavingStringId::StringId(@klass, value).int_value end end |
#type ⇒ Object
47 48 49 |
# File 'lib/acts_as_having_string_id/string_id.rb', line 47 def type :integer end |