Class: DeepStore::DAO
- Inherits:
-
Object
- Object
- DeepStore::DAO
- Defined in:
- lib/deep_store/dao.rb
Constant Summary collapse
- Result =
Class.new(OpenStruct)
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#codec ⇒ Object
readonly
Returns the value of attribute codec.
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #expand_path(path) ⇒ Object
- #get(key) ⇒ Object
- #head(key) ⇒ Object
-
#initialize(data = {}) ⇒ DAO
constructor
A new instance of DAO.
- #put(key, stream) ⇒ Object
Constructor Details
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
3 4 5 |
# File 'lib/deep_store/dao.rb', line 3 def adapter @adapter end |
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
3 4 5 |
# File 'lib/deep_store/dao.rb', line 3 def bucket @bucket end |
#codec ⇒ Object (readonly)
Returns the value of attribute codec.
3 4 5 |
# File 'lib/deep_store/dao.rb', line 3 def codec @codec end |
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
3 4 5 |
# File 'lib/deep_store/dao.rb', line 3 def resource_class @resource_class end |
Instance Method Details
#delete(key) ⇒ Object
32 33 34 |
# File 'lib/deep_store/dao.rb', line 32 def delete(key) adapter.delete_object(bucket: bucket, key: key) end |
#expand_path(path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/deep_store/dao.rb', line 36 def (path) keys = [] marker = nil while (objects = remote_objects_for(path, marker)).any? keys.concat(objects.map(&:key)) marker = objects.last.key end keys.uniq end |
#get(key) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/deep_store/dao.rb', line 19 def get(key) stream = Tempfile.new object = adapter.get_object(bucket: bucket, key: key, response_target: stream) Result.new(object: object, stream: codec.decode(stream)) rescue Aws::S3::Errors::NoSuchKey raise DeepStore::Errors::RecordNotFound end |
#head(key) ⇒ Object
13 14 15 16 17 |
# File 'lib/deep_store/dao.rb', line 13 def head(key) adapter.head_object(bucket: bucket, key: key) rescue Aws::S3::Errors::NoSuchKey raise DeepStore::Errors::RecordNotFound end |
#put(key, stream) ⇒ Object
27 28 29 30 |
# File 'lib/deep_store/dao.rb', line 27 def put(key, stream) encoded_stream = codec.encode(stream) adapter.put_object(bucket: bucket, key: key, body: encoded_stream) end |