resync-client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 892297d37e81bd989c01ec1b8727c75944272ef5
4
- data.tar.gz: 54e05162319203f118f59c2582ef2522cdf7e869
3
+ metadata.gz: 541947c7770153caf12143dc26d885166877c4bd
4
+ data.tar.gz: 5b7aa7977c089a5d09c7997d92088a695cece901
5
5
  SHA512:
6
- metadata.gz: e6ae887ca08bda37140982c22c0f8cd6594f243a826464a9178d64e3f48e43340ffa20e50b853e4d09281ac3b831fa92c6ec6c23ad373c4a8ee476fb6a43957f
7
- data.tar.gz: a841308856143cff35689d72676e4cb31e32207622b7f35582f56bd2524793ab56412d93236afa3400d6a31c593f74358e36064014ec2a4576023c4b4e3bfd20
6
+ metadata.gz: 2d4c7fa6f2ea310e34ff78c2fe956c99e1967ec4c4bba23d88a42cf5e0cc11ff5e4d84e8f88d2b79cf3f446132dbf97ab8e20ae903d90d58fa6306361c2e7c45
7
+ data.tar.gz: b23323bc0c7ca29050e4379d8596fb7d4b51f16f9f14fee80e62be12f0b4d2fd0fd34b541825d77b8d8f825b883cdf94bc569e007b02d8c8994dc9d341b5d34f
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.1.2
2
+
3
+ - Change the `:zip_packages` extension method on `ResourceDump` and `ChangeDump` to return a lazy enumerable instead of preemptively downloading all packages.
4
+
1
5
  # 0.1.1
2
6
 
3
7
  - Update to depend on [resync](https://github.com/dmolesUC3/resync) 0.1.1
@@ -1,4 +1,4 @@
1
- require_relative 'zip_package'
1
+ require_relative 'zip_packages'
2
2
 
3
3
  module Resync
4
4
  # Extends {ChangeDump} and {ResourceDump} to provide
@@ -16,10 +16,11 @@ module Resync
16
16
  end
17
17
  end
18
18
 
19
- # A list of the {ZipPackage}s for each resource
20
- # @return [Array<ZipPackage>] the zip packages for each resource
19
+ # A list (downloaded lazily) of the {ZipPackage}s for each resource
20
+ # @return [ZipPackages] the zip packages for each resource
21
21
  def zip_packages
22
- resources.map(&:zip_package)
22
+ @zip_packages ||= ZipPackages.new(resources)
23
23
  end
24
24
  end
25
+
25
26
  end
@@ -1,6 +1,6 @@
1
1
  module Resync
2
2
  class Client
3
3
  # The version of this gem.
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
6
6
  end
@@ -0,0 +1,51 @@
1
+ module Resync
2
+ # Lazily retrieves and caches the zip packages for the specified
3
+ # list of resources. The packages are cached to temporary files
4
+ # which are deleted on exit; if they are deleted while the
5
+ # interpreter is running, the behavior is undefined (but bad things
6
+ # are likely to happen).
7
+ class ZipPackages
8
+ include Enumerable
9
+
10
+ # Creates a new {ZipPackages} wrapper for the specified list
11
+ # of resources.
12
+ # @param resources [Array<Resource>] The list of resources to
13
+ # get zip packages for.
14
+ def initialize(resources)
15
+ @resources = resources
16
+ @packages = {}
17
+ end
18
+
19
+ # Gets the size of this list of packages.
20
+ # @return the size of the underlying array.
21
+ def size
22
+ @resources.size
23
+ end
24
+
25
+ # Gets the zip package at the specified index, downloading it
26
+ # if necessary.
27
+ #
28
+ # @return [ZipPackage] the zip package for the resource at the
29
+ # specified index in the underlying array.
30
+ def [](key)
31
+ resource = @resources[key]
32
+ package_for(resource)
33
+ end
34
+
35
+ # Gets the zip package for the specified resource, downloading it
36
+ # if necessary.
37
+ # @return [ZipPackage] the package for the resource
38
+ def package_for(resource)
39
+ @packages[resource] ||= resource.zip_package
40
+ end
41
+
42
+ # Lazily iterates the given block for each zip package, downloading
43
+ # as necessary.
44
+ # @param &block [Block] The block to iterate
45
+ def each
46
+ @resources.lazy.each do |resource|
47
+ yield package_for(resource)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.require_paths = ['lib']
24
24
 
25
25
  spec.add_dependency 'resync', '~> 0.1', '>= 0.1.1'
26
- spec.add_dependency 'rubyzip', '~> 1.1.7'
26
+ spec.add_dependency 'rubyzip', '~> 1.1'
27
27
 
28
28
  spec.add_development_dependency 'equivalent-xml', '~> 0.6.0'
29
29
  spec.add_development_dependency 'rake', '~> 10.4'
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ module Resync
4
+ describe ZipPackages do
5
+ it 'is lazy' do
6
+ resources = Array.new(3) { |i| Resource.new(uri: "http://example.org/res#{i}") }
7
+
8
+ zip_packages = ZipPackages.new(resources)
9
+
10
+ zip_package = instance_double(ZipPackage)
11
+ expect(resources[0]).not_to receive(:zip_package)
12
+ expect(resources[1]).not_to receive(:zip_package)
13
+ expect(resources[2]).to receive(:zip_package).and_return(zip_package)
14
+
15
+ expect(zip_packages[2]).to be(zip_package)
16
+ end
17
+
18
+ it 'caches zip packages' do
19
+ resources = Array.new(3) { |i| Resource.new(uri: "http://example.org/res#{i}") }
20
+
21
+ zip_packages = ZipPackages.new(resources)
22
+
23
+ zip_package = instance_double(ZipPackage)
24
+ expect(resources[1]).to receive(:zip_package).once.and_return(zip_package)
25
+
26
+ expect(zip_packages[1]).to be(zip_package)
27
+ expect(zip_packages[1]).to be(zip_package)
28
+ end
29
+
30
+ it 'supports lazy iteration' do
31
+ manifests = Array.new(3) { instance_double(ChangeDumpManifest) }
32
+ all_packages = Array.new(3) do |index|
33
+ zip_package = instance_double(ZipPackage)
34
+ allow(zip_package).to receive(:manifest).and_return(manifests[index])
35
+ zip_package
36
+ end
37
+ resources = Array.new(3) do |index|
38
+ resource = Resource.new(uri: "http://example.org/res#{index}")
39
+ if index > 1
40
+ expect(resource).not_to receive(:zip_package)
41
+ else
42
+ expect(resource).to receive(:zip_package).and_return(all_packages[index])
43
+ end
44
+ resource
45
+ end
46
+
47
+ zip_packages = ZipPackages.new(resources)
48
+ zip_packages.each_with_index do |zip_package, index|
49
+ expect(zip_package.manifest).to be(manifests[index])
50
+ break if index >= 1
51
+ end
52
+ end
53
+ end
54
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resync-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: resync
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 1.1.7
39
+ version: '1.1'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 1.1.7
46
+ version: '1.1'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: equivalent-xml
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -168,6 +168,7 @@ files:
168
168
  - lib/resync/client/resync_extensions.rb
169
169
  - lib/resync/client/version.rb
170
170
  - lib/resync/client/zip_package.rb
171
+ - lib/resync/client/zip_packages.rb
171
172
  - resync-client.gemspec
172
173
  - spec/data/examples/capability-list.xml
173
174
  - spec/data/examples/change-dump-manifest.xml
@@ -193,6 +194,7 @@ files:
193
194
  - spec/unit/resync/client/http_helper_spec.rb
194
195
  - spec/unit/resync/client/resync_extensions_spec.rb
195
196
  - spec/unit/resync/client/zip_package_spec.rb
197
+ - spec/unit/resync/client/zip_packages_spec.rb
196
198
  homepage: http://github.com/dmolesUC3/resync-client
197
199
  licenses:
198
200
  - MIT
@@ -213,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
215
  version: '0'
214
216
  requirements: []
215
217
  rubyforge_project:
216
- rubygems_version: 2.4.6
218
+ rubygems_version: 2.4.7
217
219
  signing_key:
218
220
  specification_version: 4
219
221
  summary: Client library for ResourceSync
@@ -242,4 +244,5 @@ test_files:
242
244
  - spec/unit/resync/client/http_helper_spec.rb
243
245
  - spec/unit/resync/client/resync_extensions_spec.rb
244
246
  - spec/unit/resync/client/zip_package_spec.rb
247
+ - spec/unit/resync/client/zip_packages_spec.rb
245
248
  has_rdoc: