Class Rufus::Cloche
In: lib/rufus/cloche/version.rb
lib/rufus/cloche.rb
Parent: Object

A cloche is a local JSON hashes store.

Warning : cloches are process-safe but not thread-safe.

Methods

delete   dir_for   do_get   get   get_many   ids   lock   match?   neutralize   new   path_for   purge_type!   put   real_ids  

Constants

VERSION = '1.0.4'
WIN = (RUBY_PLATFORM.match(/mswin|mingw/) != nil)

Attributes

dir  [R] 

Public Class methods

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.

Protected Class methods

Public Instance methods

Attempts at deleting a document. You have to pass the current version or at least the { ‘_id’ => i, ‘type’ => t, ‘_rev’ => r }.

Will return nil if the deletion is successful.

If the deletion failed because the given doc has an older revision number that the one currently stored, the doc in its freshest version will be returned.

Returns true if the deletion failed.

Gets a document (or nil if not found (or corrupted)).

Given a type, this method will return an array of all the documents for that type.

A optional second parameter may be used to select, based on a regular expression, which documents to include (match on the key ‘_id’).

Will return an empty Hash if there is no documents for a given type.

opts

:skip and :limit are understood (pagination).

If :count => true, the query will simply return the number of documents that matched.

Returns a sorted list of all the ids for a given type of documents.

Warning : trusts the ids to be identical to the filenames

Removes entirely documents of a given type.

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.

Returns a sorted list of all the ids for a given type of documents.

Actually reads each file and returns the real _id list

Protected Instance methods

[Validate]