Class: EgovUtils::Fileuid::Coder
- Inherits:
-
Object
- Object
- EgovUtils::Fileuid::Coder
- Defined in:
- lib/egov_utils/fileuid.rb
Overview
Used for ‘serialize` method in ActiveRecord
Instance Method Summary collapse
- #dump(obj) ⇒ Object
-
#initialize(attr_name, type) ⇒ Coder
constructor
A new instance of Coder.
- #load(source) ⇒ Object
Constructor Details
#initialize(attr_name, type) ⇒ Coder
Returns a new instance of Coder.
94 95 96 97 |
# File 'lib/egov_utils/fileuid.rb', line 94 def initialize(attr_name, type) @attr_name = attr_name @type = type end |
Instance Method Details
#dump(obj) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/egov_utils/fileuid.rb', line 99 def dump(obj) return if obj.nil? obj = Fileuid.new(obj, type: @type) if obj.is_a?(String) unless obj.is_a?(Fileuid) raise ::ActiveRecord::SerializationTypeMismatch, "Attribute was supposed to be a #{self}, but was a #{obj.class}. -- #{obj.inspect}" end obj.to_s end |