Class: Blobby::FilesystemStore

Inherits:
Object
  • Object
show all
Defined in:
lib/blobby/filesystem_store.rb

Overview

A BLOB store backed by a file-system.

Defined Under Namespace

Classes: StoredObject

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, options = {}, &sharding_strategy) ⇒ FilesystemStore

Returns a new instance of FilesystemStore.



19
20
21
22
23
# File 'lib/blobby/filesystem_store.rb', line 19

def initialize(dir, options = {}, &sharding_strategy)
  @dir = Pathname(dir)
  @umask = options[:umask] || File.umask
  @sharding_strategy = sharding_strategy || noop_sharding_strategy
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



25
26
27
# File 'lib/blobby/filesystem_store.rb', line 25

def dir
  @dir
end

#umaskObject (readonly)

Returns the value of attribute umask.



26
27
28
# File 'lib/blobby/filesystem_store.rb', line 26

def umask
  @umask
end

Class Method Details

.from_uri(uri) ⇒ Object



15
16
17
# File 'lib/blobby/filesystem_store.rb', line 15

def self.from_uri(uri)
  new(uri.path)
end

Instance Method Details

#[](key) ⇒ StoredObject

Access an object in the store.

Parameters:

  • key (String)

    object address

Returns:



33
34
35
36
37
# File 'lib/blobby/filesystem_store.rb', line 33

def [](key)
  KeyConstraint.must_allow!(key)
  relative_path = @sharding_strategy.call(key)
  StoredObject.new(dir + relative_path, umask)
end

#available?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/blobby/filesystem_store.rb', line 28

def available?
  dir.directory? && dir.readable? && dir.writable?
end