Class: FMCache::Jsonizer
- Inherits:
-
Object
- Object
- FMCache::Jsonizer
- Defined in:
- lib/fmcache/jsonizer.rb,
lib/fmcache/jsonizer/default_json_serializer.rb
Defined Under Namespace
Classes: DefaultJsonSerializer
Instance Method Summary collapse
- #dejsonize(hash) ⇒ { String => { String => <Hash> } }
-
#initialize(json_serializer) ⇒ Jsonizer
constructor
A new instance of Jsonizer.
- #jsonize(hash) ⇒ { String => { String => String } }
Constructor Details
#initialize(json_serializer) ⇒ Jsonizer
Returns a new instance of Jsonizer.
6 7 8 |
# File 'lib/fmcache/jsonizer.rb', line 6 def initialize(json_serializer) @json_serializer = json_serializer || DefaultJsonSerializer end |
Instance Method Details
#dejsonize(hash) ⇒ { String => { String => <Hash> } }
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fmcache/jsonizer.rb', line 26 def dejsonize(hash) r = {} hash.each do |k, v| h = {} v.each do |kk, vv| if vv.nil? h[kk] = nil else begin h[kk] = @json_serializer.load(vv) rescue h[kk] = nil end end end r[k] = h end r end |
#jsonize(hash) ⇒ { String => { String => String } }
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fmcache/jsonizer.rb', line 12 def jsonize(hash) r = {} hash.each do |k, v| h = {} v.each do |kk, vv| h[kk] = @json_serializer.dump(vv) end r[k] = h end r end |