Class: Blobby::FilesystemStore
- Inherits:
-
Object
- Object
- Blobby::FilesystemStore
- 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
-
#dir ⇒ Object
readonly
Returns the value of attribute dir.
-
#umask ⇒ Object
readonly
Returns the value of attribute umask.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ StoredObject
Access an object in the store.
- #available? ⇒ Boolean
-
#initialize(dir, options = {}, &sharding_strategy) ⇒ FilesystemStore
constructor
A new instance of FilesystemStore.
Constructor Details
#initialize(dir, options = {}, &sharding_strategy) ⇒ FilesystemStore
Returns a new instance of FilesystemStore.
17 18 19 20 21 |
# File 'lib/blobby/filesystem_store.rb', line 17 def initialize(dir, = {}, &sharding_strategy) @dir = Pathname(dir) @umask = [:umask] || File.umask @sharding_strategy = sharding_strategy || noop_sharding_strategy end |
Instance Attribute Details
#dir ⇒ Object (readonly)
Returns the value of attribute dir.
23 24 25 |
# File 'lib/blobby/filesystem_store.rb', line 23 def dir @dir end |
#umask ⇒ Object (readonly)
Returns the value of attribute umask.
24 25 26 |
# File 'lib/blobby/filesystem_store.rb', line 24 def umask @umask end |
Class Method Details
.from_uri(uri) ⇒ Object
13 14 15 |
# File 'lib/blobby/filesystem_store.rb', line 13 def self.from_uri(uri) new(uri.path) end |
Instance Method Details
#[](key) ⇒ StoredObject
Access an object in the store.
31 32 33 34 35 |
# File 'lib/blobby/filesystem_store.rb', line 31 def [](key) KeyConstraint.must_allow!(key) relative_path = @sharding_strategy.call(key) StoredObject.new(dir + relative_path, umask) end |
#available? ⇒ Boolean
26 27 28 |
# File 'lib/blobby/filesystem_store.rb', line 26 def available? dir.directory? && dir.readable? && dir.writable? end |