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.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #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.
13 14 15 16 17 |
# File 'lib/blobby/filesystem_store.rb', line 13 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.
19 20 21 |
# File 'lib/blobby/filesystem_store.rb', line 19 def dir @dir end |
#umask ⇒ Object (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
22 23 24 |
# File 'lib/blobby/filesystem_store.rb', line 22 def available? dir.directory? && dir.readable? && dir.writable? end |