Sha256: fff2aa5969aa1f5cb79e330a3da4cfc57c6ded5c98f5d539b615bdb475fcd8a1

Contents?: true

Size: 1.63 KB

Versions: 1

Compression:

Stored size: 1.63 KB

Contents

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/map"
require "rico/sorted_map"
require "rico/capped_sorted_map"

require "rico/resolver"

require "rico/version"

module Rico

  TYPES = {
    "Array" => "array",
    "List" => "list",
    "SortedSet" => "sset",
    "Set" => "set",
    "Map" => "map",
    "SortedMap" => "smap",
    "CappedSortedMap" => "csmap",
    "Value" => "value"
  }

  def self.configure
    yield self if block_given?
  end

  def self.bucket(key)
    namespaced_key = [@namespace, key].flatten.select(&:present?).join(":")
    @bucket_cache ||= {}
    @bucket_cache[namespaced_key] ||= riak.bucket(namespaced_key)
  end

  def self.namespace
    @namespace
  end

  def self.namespace=(namespace)
    @namespace = namespace
  end

  def self.options
    @options || {}
  end

  def self.options=(options)
    @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)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rico-0.5.0 lib/rico.rb