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.
19 20 21 22 23 |
# File 'lib/blobby/filesystem_store.rb', line 19 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.
25 26 27 |
# File 'lib/blobby/filesystem_store.rb', line 25 def dir @dir end |
#umask ⇒ Object (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.
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
28 29 30 |
# File 'lib/blobby/filesystem_store.rb', line 28 def available? dir.directory? && dir.readable? && dir.writable? end |