forked from technoweenie/serialized_attributes
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
organize files, add support for configurable formatters
- Loading branch information
1 parent
872c66a
commit 63fabf0
Showing
6 changed files
with
253 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
require File.dirname(__FILE__) + '/lib/serialized_attributes' | ||
$LOAD_PATH << File.dirname(__FILE__) + "/lib" | ||
require 'serialized_attributes' | ||
ActiveRecord::Base.extend SerializedAttributes::ModelMethods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'zlib' | ||
require 'stringio' | ||
|
||
module SerializedAttributes | ||
module Format | ||
module ActiveSupportJson | ||
extend self | ||
|
||
def encode(body) | ||
return nil if body.blank? | ||
s = StringIO.new | ||
z = Zlib::GzipWriter.new(s) | ||
z.write ActiveSupport::JSON.encode(body) | ||
z.close | ||
s.string | ||
end | ||
|
||
def decode(body) | ||
return {} if body.blank? | ||
s = StringIO.new(body) | ||
z = Zlib::GzipReader.new(s) | ||
hash = ActiveSupport::JSON.decode(z.read) | ||
z.close | ||
hash | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.