Class: ActiveRecord::Coders::GzipColumn
- Inherits:
-
Object
- Object
- ActiveRecord::Coders::GzipColumn
- Defined in:
- lib/serialize-rails/coders/gzip_column.rb
Overview
:nodoc:
Constant Summary collapse
- RESCUE_ERRORS =
[ ArgumentError ]
Instance Attribute Summary collapse
-
#wrapped_coder ⇒ Object
Returns the value of attribute wrapped_coder.
Instance Method Summary collapse
- #dump(obj) ⇒ Object
-
#initialize(wrap_coder) ⇒ GzipColumn
constructor
A new instance of GzipColumn.
- #load(data) ⇒ Object
- #object_class ⇒ Object
- #object_class=(value) ⇒ Object
Constructor Details
#initialize(wrap_coder) ⇒ GzipColumn
Returns a new instance of GzipColumn.
10 11 12 |
# File 'lib/serialize-rails/coders/gzip_column.rb', line 10 def initialize(wrap_coder) @wrapped_coder = wrap_coder end |
Instance Attribute Details
#wrapped_coder ⇒ Object
Returns the value of attribute wrapped_coder.
8 9 10 |
# File 'lib/serialize-rails/coders/gzip_column.rb', line 8 def wrapped_coder @wrapped_coder end |
Instance Method Details
#dump(obj) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/serialize-rails/coders/gzip_column.rb', line 22 def dump(obj) obj = wrapped_coder.dump(obj) return if obj.nil? return obj unless obj.is_a?(String) Zlib::Deflate.deflate obj end |
#load(data) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/serialize-rails/coders/gzip_column.rb', line 30 def load(data) return object_class.new if object_class != Object && data.nil? return data unless data.is_a?(String) begin ungzipped_data = Zlib::Inflate.inflate(data) wrapped_coder.load(ungzipped_data) rescue *RESCUE_ERRORS data end end |
#object_class ⇒ Object
14 15 16 |
# File 'lib/serialize-rails/coders/gzip_column.rb', line 14 def object_class wrapped_coder.object_class end |
#object_class=(value) ⇒ Object
18 19 20 |
# File 'lib/serialize-rails/coders/gzip_column.rb', line 18 def object_class=(value) wrapped_coder.object_class = value end |