lib/rico.rb in rico-0.2.0 vs lib/rico.rb in rico-0.3.0

- old
+ new

@@ -1,26 +1,34 @@ require "riak" require "rico/object" +require "rico/collection" +require "rico/value" + require "rico/array" require "rico/list" require "rico/set" require "rico/sorted_set" -require "rico/value" +require "rico/map" +require "rico/sorted_map" +require "rico/capped_sorted_map" + require "rico/resolver" require "rico/version" module Rico TYPES = { "Array" => "array", "List" => "list", + "Map" => "map", "Set" => "set", "SortedSet" => "sset", + "SortedMap" => "smap", "Value" => "value" } def self.configure yield self if block_given? @@ -48,9 +56,38 @@ @options = options end def self.riak Thread.current[:riak] ||= Riak::Client.new(options) + end +end + +module Riak + module Serializers + module ApplicationXGZIP + extend self + + def dump(object) + json = ApplicationJSON.dump(object) + io = StringIO.new + gz = Zlib::GzipWriter.new(io) + gz.write(json) + gz.close + + io.string + end + + def load(string) + io = StringIO.new(string) + gz = Zlib::GzipReader.new(io) + json = gz.read + gz.close + + ApplicationJSON.load(json) + end + end + + Serializers['application/x-gzip'] = ApplicationXGZIP end end Riak::RObject.on_conflict(&Rico::Resolver.to_proc)