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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of FilesystemStore.



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

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.



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

def dir
  @dir
end

#umaskObject (readonly)

Returns the value of attribute umask.



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

def umask
  @umask
end

Instance Method Details

#[](key) ⇒ Object



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

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

#available?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/blobby/filesystem_store.rb', line 22

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