deep_store 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58c4bcca38301541eb6c59de4eeb1bb5987da2fe
4
- data.tar.gz: 0bbed2225a84b1b09732deeee0126a9e7029fc90
3
+ metadata.gz: 05957ff7e34589fb61cd62c25a02b1ee73e3a424
4
+ data.tar.gz: 4c75e8e9b0db6a23626bf629ff015aa39df507c8
5
5
  SHA512:
6
- metadata.gz: 414f73c84fc194b68199fd84cd05203d1d5850588ffb716de7ef3b5638447dc0e37f2a73c91f52b2f267c29f8bfeb9a033c580188e79d18082129ee622b22999
7
- data.tar.gz: a4c36ee301a5730e9c6450bc1064003d885661805344e948502c339ff9215bf762150f0f6c8cb2abbf86485a8db0cf10aaaaf103f63db11c0a484975db309801
6
+ metadata.gz: 1ac2b9f699f0612f41131b35098683a4c4ae61de5f9936377a434816ea84efdf8cf8aa945a6217af146c767b0a75a226dace222bfec854e32200dbd22bc9b31e
7
+ data.tar.gz: 9471c6de8084b182c19fe188aa2fefc462f799a5a49316514027c542823cd0d84686a46ab709c372a30c6381a43829cb56da6f6f35570f910843ae2337740f6d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [0.2.0] 2016-10-24
4
+ ### Added
5
+ - DAO specs
6
+ - Model#finalize method to manually clean model streams
7
+ - Model#unlink to manually delete temporary files
8
+
9
+ ### Fixed
10
+ - ObjectSpace model finalizer
11
+ - Capture `Aws::S3::Errors::NotFound`
12
+
13
+ ### Changed
14
+ - Moved attribute methods to DeepStore::Model::Attributes
15
+
3
16
  ## [0.1.1] 2016-10-14
4
17
  ### Fixed
5
18
  - Gem packaging
@@ -14,6 +14,8 @@ module DeepStore
14
14
  adapter.head_object(bucket: bucket, key: key)
15
15
  rescue Aws::S3::Errors::NoSuchKey
16
16
  raise DeepStore::Errors::RecordNotFound
17
+ rescue Aws::S3::Errors::NotFound
18
+ raise DeepStore::Errors::RecordNotFound
17
19
  end
18
20
 
19
21
  def get(key)
@@ -22,6 +24,8 @@ module DeepStore
22
24
  Result.new(object: object, stream: codec.decode(stream))
23
25
  rescue Aws::S3::Errors::NoSuchKey
24
26
  raise DeepStore::Errors::RecordNotFound
27
+ rescue Aws::S3::Errors::NotFound
28
+ raise DeepStore::Errors::RecordNotFound
25
29
  end
26
30
 
27
31
  def put(key, stream)
@@ -0,0 +1,17 @@
1
+ module DeepStore
2
+ module Model
3
+ module Attributes
4
+ def self.included(base)
5
+ base.class_eval do
6
+ def initialize(params = {})
7
+ params.each { |k, v| send("#{k}=", v) }
8
+ end
9
+
10
+ def attributes
11
+ Hash[__schema__.keys.map { |k| [k, send(k)] }]
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -5,7 +5,9 @@ module DeepStore
5
5
  base.class_eval do
6
6
  extend Forwardable
7
7
 
8
- def_delegators :content, :read, :write, :rewind, :each, :puts, :close
8
+ attr_reader :sweeper
9
+
10
+ def_delegators :content, :read, :write, :rewind, :each, :puts, :close, :unlink
9
11
 
10
12
  def reload
11
13
  @content = nil
@@ -17,8 +19,12 @@ module DeepStore
17
19
  end
18
20
 
19
21
  def content=(stream)
20
- ObjectSpace.define_finalizer(self, -> { stream.close })
21
22
  @content = stream
23
+ @sweeper = Sweeper.register(self, stream)
24
+ end
25
+
26
+ def finalize
27
+ sweeper&.finalize
22
28
  end
23
29
  end
24
30
  end
@@ -4,6 +4,7 @@ module DeepStore
4
4
  autoload :KeyFactory, File.expand_path('../model/key_factory', __FILE__)
5
5
  autoload :ContentInterface, File.expand_path('../model/content_interface', __FILE__)
6
6
  autoload :DSL, File.expand_path('../model/dsl', __FILE__)
7
+ autoload :Attributes, File.expand_path('../model/attributes', __FILE__)
7
8
 
8
9
  def self.included(base)
9
10
  base.extend(ClassMethods)
@@ -14,14 +15,7 @@ module DeepStore
14
15
  include ActiveModel::Validations
15
16
  include Persistence
16
17
  include ContentInterface
17
-
18
- def initialize(data = {})
19
- data.each { |k, v| send("#{k}=", v) }
20
- end
21
-
22
- def attributes
23
- Hash[__schema__.keys.map { |k| [k, send(k)] }]
24
- end
18
+ include Attributes
25
19
 
26
20
  private
27
21
 
@@ -0,0 +1,24 @@
1
+ module DeepStore
2
+ class Sweeper
3
+ attr_reader :stream
4
+
5
+ def self.register(object, stream)
6
+ sweeper = Sweeper.new(stream)
7
+ ObjectSpace.define_finalizer(object, sweeper)
8
+ sweeper
9
+ end
10
+
11
+ def initialize(stream)
12
+ @stream = stream
13
+ end
14
+
15
+ def call(_object_id)
16
+ finalize
17
+ end
18
+
19
+ def finalize
20
+ stream.close if stream.respond_to?(:close)
21
+ stream.unlink if stream.respond_to?(:unlink)
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module DeepStore
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/deep_store.rb CHANGED
@@ -4,6 +4,7 @@ require 'ostruct'
4
4
  require 'aws-sdk'
5
5
  require 'active_model'
6
6
  require 'mime/types'
7
+ require 'fileutils'
7
8
 
8
9
  module DeepStore
9
10
  autoload :Settings, 'deep_store/settings'
@@ -16,6 +17,7 @@ module DeepStore
16
17
  autoload :Codecs, 'deep_store/codecs'
17
18
  autoload :Operations, 'deep_store/operations'
18
19
  autoload :KeyParser, 'deep_store/key_parser'
20
+ autoload :Sweeper, 'deep_store/sweeper'
19
21
  autoload :Errors, 'deep_store/errors'
20
22
 
21
23
  def self.adapter
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Wiermann
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-14 00:00:00.000000000 Z
11
+ date: 2016-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -181,6 +181,7 @@ files:
181
181
  - lib/deep_store/errors.rb
182
182
  - lib/deep_store/key_parser.rb
183
183
  - lib/deep_store/model.rb
184
+ - lib/deep_store/model/attributes.rb
184
185
  - lib/deep_store/model/content_interface.rb
185
186
  - lib/deep_store/model/dsl.rb
186
187
  - lib/deep_store/model/key_factory.rb
@@ -193,6 +194,7 @@ files:
193
194
  - lib/deep_store/operations/where_query.rb
194
195
  - lib/deep_store/repository.rb
195
196
  - lib/deep_store/settings.rb
197
+ - lib/deep_store/sweeper.rb
196
198
  - lib/deep_store/version.rb
197
199
  homepage: https://github.com/marcelow/deep_store
198
200
  licenses: