Class: Thingfish::Datastore::Filesystem

Inherits:
Thingfish::Datastore
  • Object
show all
Extended by:
Configurability, Loggability, Strelka::MethodUtilities, Normalization
Defined in:
lib/thingfish/datastore/filesystem.rb

Overview

A hashed-directory hierarchy filesystem datastore for Thingfish

Constant Summary collapse

VERSION =

Package version

'0.2.0'
REVISION =

Version control revision

%q$Revision: cb4954dd5c6e $
HASH_DEPTH =

The number of subdirectories to use in the hashed directory tree. Must be 2, 4, or 8

4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFilesystem

Create a new Filesystem Datastore.



46
47
48
49
# File 'lib/thingfish/datastore/filesystem.rb', line 46

def initialize
  super
  @root_path = self.class.root_path
end

Instance Attribute Details

#root_pathObject (readonly)

The root path of the datastore



58
59
60
# File 'lib/thingfish/datastore/filesystem.rb', line 58

def root_path
  @root_path
end

Instance Method Details

#fetch(oid) ⇒ Object

Fetch the data corresponding to the given oid as an IOish object.



77
78
79
# File 'lib/thingfish/datastore/filesystem.rb', line 77

def fetch( oid )
  return self.retrieve( oid )
end

#include?(oid) ⇒ Boolean

Returns true if the datastore has a file for the specified oid.

Returns:

  • (Boolean)


83
84
85
# File 'lib/thingfish/datastore/filesystem.rb', line 83

def include?( oid )
  return self.hashed_path( oid ).exist?
end

#remove(oid) ⇒ Object

Remove the data associated with oid from the Datastore.



89
90
91
# File 'lib/thingfish/datastore/filesystem.rb', line 89

def remove( oid )
  return self.hashed_path( oid ).unlink
end

#replace(oid, io) ⇒ Object

Replace the existing object associated with oid with the data read from the given io.



96
97
98
99
100
101
102
103
# File 'lib/thingfish/datastore/filesystem.rb', line 96

def replace( oid, io )
  pos = io.pos
  self.store( oid, io )

  return true
ensure
  io.pos = pos if pos
end

#save(io) ⇒ Object

Save the data read from the specified io and return an ID that can be used to fetch it later.



64
65
66
67
68
69
70
71
72
73
# File 'lib/thingfish/datastore/filesystem.rb', line 64

def save( io )
  oid = make_object_id()

  pos = io.pos
  self.store( oid, io )

  return oid
ensure
  io.pos = pos if pos
end