def put(doc, opts={})

      opts = opts.inject({}) { |h, (k, v)| h[k.to_s] = v; h }

      doc = Rufus::Json.dup(doc) unless opts['update_rev']
        # work with a copy, don't touch original

      type, key = doc['type'], doc['_id']

      raise(
        ArgumentError.new("missing values for keys 'type' and/or '_id'")
      ) if type.nil? || key.nil?

      rev = (doc['_rev'] ||= -1)

      raise(
        ArgumentError.new("values for '_rev' must be positive integers")
      ) if rev.class != Fixnum && rev.class != Bignum

      r =
        lock(rev == -1 ? :create : :write, type, key) do |file|

          cur = do_get(file)

          return cur if cur && cur['_rev'] != doc['_rev']
          return true if cur.nil? && doc['_rev'] != -1

          doc['_rev'] += 1

          File.open(file.path, 'wb') { |io| io.write(Rufus::Json.encode(doc)) }
        end

      r == false ? true : nil
    end
def put(doc, opts={})

      opts = opts.inject({}) { |h, (k, v)| h[k.to_s] = v; h }

      doc = Rufus::Json.dup(doc) unless opts['update_rev']
        # work with a copy, don't touch original

      type, key = doc['type'], doc['_id']

      raise(
        ArgumentError.new("missing values for keys 'type' and/or '_id'")
      ) if type.nil? || key.nil?

      rev = (doc['_rev'] ||= -1)

      raise(
        ArgumentError.new("values for '_rev' must be positive integers")
      ) if rev.class != Fixnum && rev.class != Bignum

      r =
        lock(rev == -1 ? :create : :write, type, key) do |file|

          cur = do_get(file)

          return cur if cur && cur['_rev'] != doc['_rev']
          return true if cur.nil? && doc['_rev'] != -1

          doc['_rev'] += 1

          File.open(file.path, 'wb') { |io| io.write(Rufus::Json.encode(doc)) }
        end

      r == false ? true : nil
    end
Creates a new 'cloche'.

 There are 2 options :

 * :dir : to specify the directory into which the cloche data is store
 * :nolock : when set to true, no flock is used

 On the Windows platform, :nolock is set to true automatically.

 Puts a document (Hash) under the cloche.

 If the document is brand new, it will be given a revision number '_rev'
 of 0.

 If the document already exists in the cloche and the version to put
 has an older (different) revision number than the one currently stored,
 put will fail and return the current version of the doc.

 If the put is successful, nil is returned.