resync-client 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -9
- data/CHANGES.md +6 -0
- data/lib/resync/client/mixins/bitstream_resource.rb +5 -5
- data/lib/resync/client/mixins/client_delegator.rb +5 -5
- data/lib/resync/client/mixins/downloadable.rb +10 -1
- data/lib/resync/client/mixins/{zipped_resource_list.rb → dump.rb} +12 -2
- data/lib/resync/client/mixins/dump_index.rb +33 -0
- data/lib/resync/client/mixins/dump_manifest.rb +40 -0
- data/lib/resync/client/mixins/link_client_delegate.rb +6 -1
- data/lib/resync/client/mixins/list_index.rb +33 -0
- data/lib/resync/client/mixins/resource_client_delegate.rb +6 -1
- data/lib/resync/client/mixins/zipped_resource.rb +2 -1
- data/lib/resync/client/version.rb +1 -1
- data/lib/resync/client/zip/zip_package.rb +1 -1
- data/lib/resync/client/zip/zip_packages.rb +11 -1
- data/lib/resync/client.rb +1 -1
- data/spec/data/examples/resource-list-1.xml +24 -0
- data/spec/data/examples/resource-list-2.xml +24 -0
- data/spec/data/examples/resource-list-3.xml +24 -0
- data/spec/unit/resync/client/dump_index_spec.rb +108 -0
- data/spec/unit/resync/client/{zipped_resource_list_spec.rb → dump_spec.rb} +1 -1
- data/spec/unit/resync/client/list_index_spec.rb +107 -0
- data/spec/unit/resync/client/zip_packages_spec.rb +24 -0
- metadata +18 -7
- data/lib/resync/client/mixins/bitstream_resource_list.rb +0 -29
- data/lib/resync/extensions.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8314c851c5631164009f9a2d88d0c3d403cc70ad
|
4
|
+
data.tar.gz: 533203c8b735acb0c29063efa8112feb80921e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2be76b5aaf5d2141a009ef77336ebb1d78877971d94a1069e369bb25e97251726b548898f3906e9852097e53cde6ec28f68638bebfd14c90f6c124bddbcd14d9
|
7
|
+
data.tar.gz: 0071b77513fc26fee16832f7885e414801e65c4895df3911c4093b5fff0c187c478209605447db5cf9f27eb97a4ae5e457bb093f436eed3bf7cce0c03fe5439c
|
data/.gitignore
CHANGED
@@ -15,15 +15,9 @@
|
|
15
15
|
*.a
|
16
16
|
mkmf.log
|
17
17
|
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
log/*.log
|
22
|
-
spec/dummy/db/*.sqlite3
|
23
|
-
spec/dummy/db/*.sqlite3-journal
|
24
|
-
spec/dummy/log/*.log
|
25
|
-
spec/dummy/tmp/
|
26
|
-
spec/dummy/.sass-cache
|
18
|
+
# gem build
|
19
|
+
|
20
|
+
*.gem
|
27
21
|
|
28
22
|
# IntellJ
|
29
23
|
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
# 0.2.4
|
2
|
+
|
3
|
+
- Added `#all_resources` to transparently download and flatten lists in `ChangeListIndex` and `ResourceListIndex`
|
4
|
+
- Added `#all_zip_packages` to transparently download and flatten dumps in `ChangeDumpIndex` and `ResourceDumpIndex`
|
5
|
+
- Fix issue where documentation on mixin modules was mistakenly applied to the `Resync` module
|
6
|
+
|
1
7
|
# 0.2.3
|
2
8
|
|
3
9
|
- Update to depend on [resync](https://github.com/dmolesUC3/resync) 0.2.2
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require_relative '../zip'
|
2
2
|
|
3
|
-
# A resource that refers to a bitsream within a zipped bitstream package.
|
4
|
-
#
|
5
|
-
# @!attribute [rw] zip_package_delegate
|
6
|
-
# @return [ZipPackage] the provider of the containing package,
|
7
|
-
# e.g. its manifest
|
8
3
|
module Resync
|
9
4
|
class Client
|
10
5
|
module Mixins
|
6
|
+
# A resource that refers to a bitsream within a zipped bitstream package.
|
7
|
+
#
|
8
|
+
# @!attribute [rw] zip_package_delegate
|
9
|
+
# @return [ZipPackage] the provider of the containing package,
|
10
|
+
# e.g. its manifest
|
11
11
|
module BitstreamResource
|
12
12
|
attr_accessor :zip_package_delegate
|
13
13
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require_relative '../../client'
|
2
2
|
|
3
|
-
# An object that delegates to another to provide a {Client} for downloading
|
4
|
-
# resources and links.
|
5
|
-
#
|
6
|
-
# @!attribute [rw] client_delegate
|
7
|
-
# @return [#client] The client provider.
|
8
3
|
module Resync
|
9
4
|
class Client
|
10
5
|
module Mixins
|
6
|
+
# An object that delegates to another to provide a {Client} for downloading
|
7
|
+
# resources and links.
|
8
|
+
#
|
9
|
+
# @!attribute [rw] client_delegate
|
10
|
+
# @return [#client] The client provider.
|
11
11
|
module ClientDelegator
|
12
12
|
attr_accessor :client_delegate
|
13
13
|
|
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'resync'
|
1
2
|
require_relative 'client_delegator'
|
2
3
|
|
3
|
-
# A downloadable resource or link.
|
4
4
|
module Resync
|
5
5
|
class Client
|
6
6
|
module Mixins
|
7
|
+
# A downloadable resource or link.
|
7
8
|
module Downloadable
|
8
9
|
prepend ClientDelegator
|
9
10
|
|
@@ -33,4 +34,12 @@ module Resync
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
end
|
37
|
+
|
38
|
+
class Link
|
39
|
+
prepend Client::Mixins::Downloadable
|
40
|
+
end
|
41
|
+
|
42
|
+
class Resource
|
43
|
+
prepend Client::Mixins::Downloadable
|
44
|
+
end
|
36
45
|
end
|
@@ -1,14 +1,16 @@
|
|
1
|
+
require 'resync'
|
1
2
|
require_relative '../zip'
|
2
3
|
require_relative 'zipped_resource'
|
3
4
|
|
4
|
-
# A list of resources each of which refers to a zipped bitstream package.
|
5
5
|
module Resync
|
6
6
|
class Client
|
7
7
|
module Mixins
|
8
|
-
|
8
|
+
# A list of resources each of which refers to a zipped bitstream package.
|
9
|
+
module Dump
|
9
10
|
def resources=(value)
|
10
11
|
super
|
11
12
|
resources.each do |r|
|
13
|
+
next if r.respond_to?(:zip_package)
|
12
14
|
class << r
|
13
15
|
prepend ZippedResource
|
14
16
|
end
|
@@ -23,4 +25,12 @@ module Resync
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
28
|
+
|
29
|
+
class ResourceDump
|
30
|
+
prepend Client::Mixins::Dump
|
31
|
+
end
|
32
|
+
|
33
|
+
class ChangeDump
|
34
|
+
prepend Client::Mixins::Dump
|
35
|
+
end
|
26
36
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'resync'
|
2
|
+
require_relative 'resource_client_delegate'
|
3
|
+
|
4
|
+
module Resync
|
5
|
+
class Client
|
6
|
+
module Mixins
|
7
|
+
# A resource container whose resources are {ZippedResourceList}s
|
8
|
+
module DumpIndex
|
9
|
+
prepend ResourceClientDelegate
|
10
|
+
|
11
|
+
# Downloads and parses each resource list and returns a flattened enumeration
|
12
|
+
# of all zip packages in each contained list. Each contained list is only downloaded
|
13
|
+
# as needed, and only downloaded once.
|
14
|
+
# @return [Enumerator::Lazy<Resync::Client::Zip::ZipPackages>] the flattened enumeration of resources
|
15
|
+
def all_zip_packages
|
16
|
+
@zipped_resource_lists ||= {}
|
17
|
+
resources.flat_map do |r|
|
18
|
+
@zipped_resource_lists[r] ||= r.get_and_parse
|
19
|
+
@zipped_resource_lists[r].respond_to?(:zip_packages) ? @zipped_resource_lists[r].zip_packages : []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ChangeDumpIndex
|
27
|
+
prepend Client::Mixins::DumpIndex
|
28
|
+
end
|
29
|
+
|
30
|
+
class ResourceDumpIndex
|
31
|
+
prepend Client::Mixins::DumpIndex
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'resync'
|
2
|
+
require_relative '../zip'
|
3
|
+
require_relative 'bitstream_resource'
|
4
|
+
|
5
|
+
module Resync
|
6
|
+
class Client
|
7
|
+
module Mixins
|
8
|
+
# A list of resources within a single zipped bitstream package, e.g. as provided
|
9
|
+
# by the package manifest.
|
10
|
+
#
|
11
|
+
# @!attribute [rw] zip_package
|
12
|
+
# @return [ZipPackage] the package.
|
13
|
+
module DumpManifest
|
14
|
+
attr_accessor :zip_package
|
15
|
+
|
16
|
+
# Makes each provided resource a {BitstreamResource}
|
17
|
+
# @param value [Array<Resource>] the resources for this list
|
18
|
+
def resources=(value)
|
19
|
+
super
|
20
|
+
resources.each do |r|
|
21
|
+
unless r.respond_to?(:bitstream) && r.respond_to?(:containing_package)
|
22
|
+
class << r
|
23
|
+
prepend BitstreamResource
|
24
|
+
end
|
25
|
+
end
|
26
|
+
r.zip_package_delegate = self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class ResourceDumpManifest
|
34
|
+
prepend Client::Mixins::DumpManifest
|
35
|
+
end
|
36
|
+
|
37
|
+
class ChangeDumpManifest
|
38
|
+
prepend Client::Mixins::DumpManifest
|
39
|
+
end
|
40
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'resync'
|
1
2
|
require_relative 'client_delegator'
|
2
3
|
|
3
|
-
# A link container that is capable of providing those resources with a {Client}
|
4
4
|
module Resync
|
5
5
|
class Client
|
6
6
|
module Mixins
|
7
|
+
# A link container that is capable of providing those resources with a {Client}
|
7
8
|
module LinkClientDelegate
|
8
9
|
prepend ClientDelegator
|
9
10
|
|
@@ -16,4 +17,8 @@ module Resync
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
21
|
+
class Augmented
|
22
|
+
prepend Client::Mixins::LinkClientDelegate
|
23
|
+
end
|
19
24
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'resync'
|
2
|
+
require_relative 'resource_client_delegate'
|
3
|
+
|
4
|
+
module Resync
|
5
|
+
class Client
|
6
|
+
module Mixins
|
7
|
+
# A resource container whose resources are, themselves, resource containers
|
8
|
+
module ListIndex
|
9
|
+
prepend ResourceClientDelegate
|
10
|
+
|
11
|
+
# Downloads and parses each resource list and returns a flattened enumeration
|
12
|
+
# of all resources in each contained list. Each contained list is only downloaded
|
13
|
+
# as needed, and only downloaded once.
|
14
|
+
# @return [Enumerator::Lazy<Resync::Resource>] the flattened enumeration of resources
|
15
|
+
def all_resources
|
16
|
+
@resource_lists ||= {}
|
17
|
+
resources.flat_map do |r|
|
18
|
+
@resource_lists[r] ||= r.get_and_parse
|
19
|
+
@resource_lists[r].resources
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ChangeListIndex
|
27
|
+
prepend Client::Mixins::ListIndex
|
28
|
+
end
|
29
|
+
|
30
|
+
class ResourceListIndex
|
31
|
+
prepend Client::Mixins::ListIndex
|
32
|
+
end
|
33
|
+
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'resync'
|
1
2
|
require_relative 'client_delegator'
|
2
3
|
|
3
|
-
# A resource container that is capable of providing those resources with a {Client}
|
4
4
|
module Resync
|
5
5
|
class Client
|
6
6
|
module Mixins
|
7
|
+
# A resource container that is capable of providing those resources with a {Client}
|
7
8
|
module ResourceClientDelegate
|
8
9
|
prepend ClientDelegator
|
9
10
|
|
@@ -16,4 +17,8 @@ module Resync
|
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
21
|
+
class BaseResourceList
|
22
|
+
prepend Client::Mixins::ResourceClientDelegate
|
23
|
+
end
|
19
24
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require_relative '../zip'
|
2
2
|
require_relative 'downloadable'
|
3
3
|
|
4
|
-
# A resource that refers to a zipped bitstream package.
|
5
4
|
module Resync
|
6
5
|
class Client
|
7
6
|
module Mixins
|
7
|
+
# A resource that refers to a zipped bitstream package.
|
8
8
|
module ZippedResource
|
9
9
|
prepend Downloadable
|
10
10
|
|
@@ -12,6 +12,7 @@ module Resync
|
|
12
12
|
# it to a temporary file if necessary.
|
13
13
|
# @return [Resync::Client::Zip::ZipPackage] the zipped contents of this resource
|
14
14
|
def zip_package
|
15
|
+
puts self
|
15
16
|
@zip_package ||= Resync::Client::Zip::ZipPackage.new(download_to_temp_file)
|
16
17
|
end
|
17
18
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'resync'
|
2
|
-
require_relative '
|
2
|
+
require_relative '../mixins'
|
3
3
|
require_relative 'zip_package'
|
4
4
|
|
5
5
|
module Resync
|
@@ -53,6 +53,16 @@ module Resync
|
|
53
53
|
yield package_for(resource)
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
# Eagerly gets the zip package for each resource, downloading
|
58
|
+
# as necessary. (For compatbility with {::Enumerator::Lazy#flat_map})
|
59
|
+
# @return [Array<ZipPackage>] the zip package for each resource
|
60
|
+
def force
|
61
|
+
@resources.map { |r| package_for(r) }.to_a
|
62
|
+
end
|
63
|
+
|
64
|
+
# Alias for {#force} (for compatbility with {::Enumerable#flat_map})
|
65
|
+
alias_method :to_ary, :force
|
56
66
|
end
|
57
67
|
end
|
58
68
|
end
|
data/lib/resync/client.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
3
|
+
xmlns:rs="http://www.openarchives.org/rs/terms/">
|
4
|
+
<rs:ln rel="up"
|
5
|
+
href="http://example.com/dataset1/capabilitylist.xml"/>
|
6
|
+
<rs:ln rel="index"
|
7
|
+
href="http://example.com/dataset1/resourcelist-index.xml"/>
|
8
|
+
<rs:md capability="resourcelist"
|
9
|
+
at="2013-01-03T09:00:00Z"/>
|
10
|
+
<url>
|
11
|
+
<loc>http://example.com/res1</loc>
|
12
|
+
<lastmod>2013-01-02T13:00:00Z</lastmod>
|
13
|
+
<rs:md hash="md5:1584abdf8ebdc9802ac0c6a7402c8753"
|
14
|
+
length="4385"
|
15
|
+
type="application/pdf"/>
|
16
|
+
</url>
|
17
|
+
<url>
|
18
|
+
<loc>http://example.com/res2</loc>
|
19
|
+
<lastmod>2013-01-02T14:00:00Z</lastmod>
|
20
|
+
<rs:md hash="md5:4556abdf8ebdc9802ac0c6a7402c9881"
|
21
|
+
length="883"
|
22
|
+
type="image/png"/>
|
23
|
+
</url>
|
24
|
+
</urlset>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
3
|
+
xmlns:rs="http://www.openarchives.org/rs/terms/">
|
4
|
+
<rs:ln rel="up"
|
5
|
+
href="http://example.com/dataset1/capabilitylist.xml"/>
|
6
|
+
<rs:ln rel="index"
|
7
|
+
href="http://example.com/dataset1/resourcelist-index.xml"/>
|
8
|
+
<rs:md capability="resourcelist"
|
9
|
+
at="2013-01-03T09:00:00Z"/>
|
10
|
+
<url>
|
11
|
+
<loc>http://example.com/res3</loc>
|
12
|
+
<lastmod>2013-01-02T13:00:00Z</lastmod>
|
13
|
+
<rs:md hash="md5:1584abdf8ebdc9802ac0c6a7402c8753"
|
14
|
+
length="4385"
|
15
|
+
type="application/pdf"/>
|
16
|
+
</url>
|
17
|
+
<url>
|
18
|
+
<loc>http://example.com/res4</loc>
|
19
|
+
<lastmod>2013-01-02T14:00:00Z</lastmod>
|
20
|
+
<rs:md hash="md5:4556abdf8ebdc9802ac0c6a7402c9881"
|
21
|
+
length="883"
|
22
|
+
type="image/png"/>
|
23
|
+
</url>
|
24
|
+
</urlset>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
|
3
|
+
xmlns:rs="http://www.openarchives.org/rs/terms/">
|
4
|
+
<rs:ln rel="up"
|
5
|
+
href="http://example.com/dataset1/capabilitylist.xml"/>
|
6
|
+
<rs:ln rel="index"
|
7
|
+
href="http://example.com/dataset1/resourcelist-index.xml"/>
|
8
|
+
<rs:md capability="resourcelist"
|
9
|
+
at="2013-01-03T09:00:00Z"/>
|
10
|
+
<url>
|
11
|
+
<loc>http://example.com/res5</loc>
|
12
|
+
<lastmod>2013-01-02T13:00:00Z</lastmod>
|
13
|
+
<rs:md hash="md5:1584abdf8ebdc9802ac0c6a7402c8753"
|
14
|
+
length="4385"
|
15
|
+
type="application/pdf"/>
|
16
|
+
</url>
|
17
|
+
<url>
|
18
|
+
<loc>http://example.com/res6</loc>
|
19
|
+
<lastmod>2013-01-02T14:00:00Z</lastmod>
|
20
|
+
<rs:md hash="md5:4556abdf8ebdc9802ac0c6a7402c9881"
|
21
|
+
length="883"
|
22
|
+
type="image/png"/>
|
23
|
+
</url>
|
24
|
+
</urlset>
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Resync
|
4
|
+
class Client
|
5
|
+
module Mixins
|
6
|
+
describe DumpIndex do
|
7
|
+
before(:each) do
|
8
|
+
@helper = instance_double(Client::HTTPHelper)
|
9
|
+
@client = Client.new(helper: @helper)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#all_zip_packages' do
|
13
|
+
it 'flattens the child resourcelists' do
|
14
|
+
resources = Array.new(6) { instance_double(ZippedResource) }
|
15
|
+
all_zip_packages = Array.new(6) do |i|
|
16
|
+
zip_package = instance_double(Zip::ZipPackage)
|
17
|
+
expect(resources[i]).to receive(:zip_package).once.and_return(zip_package)
|
18
|
+
allow(resources[i]).to receive(:client_delegate=)
|
19
|
+
zip_package
|
20
|
+
end
|
21
|
+
|
22
|
+
dump1 = ResourceDump.new(resources: resources[0, 3])
|
23
|
+
dump2 = ResourceDump.new(resources: resources[3, 3])
|
24
|
+
|
25
|
+
dump1_resource = instance_double(Resource)
|
26
|
+
allow(dump1_resource).to receive(:client_delegate=)
|
27
|
+
expect(dump1_resource).to receive(:get_and_parse).and_return(dump1)
|
28
|
+
|
29
|
+
dump2_resource = instance_double(Resource)
|
30
|
+
allow(dump2_resource).to receive(:client_delegate=)
|
31
|
+
expect(dump2_resource).to receive(:get_and_parse).and_return(dump2)
|
32
|
+
|
33
|
+
index = ResourceDumpIndex.new(resources: [dump1_resource, dump2_resource])
|
34
|
+
all_packages = index.all_zip_packages
|
35
|
+
|
36
|
+
expect(all_packages.to_a).to eq(all_zip_packages)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is lazy enough not to download anything till it\'s iterated' do
|
40
|
+
dump1_resource = instance_double(Resource)
|
41
|
+
allow(dump1_resource).to receive(:client_delegate=)
|
42
|
+
expect(dump1_resource).not_to receive(:get_and_parse)
|
43
|
+
|
44
|
+
dump2_resource = instance_double(Resource)
|
45
|
+
allow(dump2_resource).to receive(:client_delegate=)
|
46
|
+
expect(dump2_resource).not_to receive(:get_and_parse)
|
47
|
+
|
48
|
+
index = ResourceDumpIndex.new(resources: [dump1_resource, dump2_resource])
|
49
|
+
index.all_zip_packages
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'is lazy enough not to download resources it doesn\'t need' do
|
53
|
+
resources = Array.new(3) { instance_double(ZippedResource) }
|
54
|
+
resources.each do |r|
|
55
|
+
allow(r).to receive(:client_delegate=)
|
56
|
+
zip_package = instance_double(Zip::ZipPackage)
|
57
|
+
expect(r).to receive(:zip_package).once.and_return(zip_package)
|
58
|
+
end
|
59
|
+
|
60
|
+
dump1 = ResourceDump.new(resources: resources[0, 3])
|
61
|
+
|
62
|
+
dump1_resource = instance_double(Resource)
|
63
|
+
allow(dump1_resource).to receive(:client_delegate=)
|
64
|
+
expect(dump1_resource).to receive(:get_and_parse).and_return(dump1)
|
65
|
+
|
66
|
+
dump2_resource = instance_double(Resource)
|
67
|
+
allow(dump2_resource).to receive(:client_delegate=)
|
68
|
+
expect(dump2_resource).not_to receive(:get_and_parse)
|
69
|
+
|
70
|
+
index = ResourceDumpIndex.new(resources: [dump1_resource, dump2_resource])
|
71
|
+
index.all_zip_packages.each_with_index do |_, i|
|
72
|
+
break if i >= 2
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'caches downloaded resources' do
|
77
|
+
resources = Array.new(6) { instance_double(ZippedResource) }
|
78
|
+
resources.each do |r|
|
79
|
+
allow(r).to receive(:client_delegate=)
|
80
|
+
zip_package = instance_double(Zip::ZipPackage)
|
81
|
+
expect(r).to receive(:zip_package).once.and_return(zip_package)
|
82
|
+
end
|
83
|
+
|
84
|
+
dump1 = ResourceDump.new(resources: resources[0, 3])
|
85
|
+
dump2 = ResourceDump.new(resources: resources[3, 3])
|
86
|
+
|
87
|
+
dump1_resource = instance_double(Resource)
|
88
|
+
allow(dump1_resource).to receive(:client_delegate=)
|
89
|
+
expect(dump1_resource).to receive(:get_and_parse).once.and_return(dump1)
|
90
|
+
|
91
|
+
dump2_resource = instance_double(Resource)
|
92
|
+
allow(dump2_resource).to receive(:client_delegate=)
|
93
|
+
expect(dump2_resource).to receive(:get_and_parse).once.and_return(dump2)
|
94
|
+
|
95
|
+
index = ResourceDumpIndex.new(resources: [dump1_resource, dump2_resource])
|
96
|
+
all_packages = index.all_zip_packages
|
97
|
+
|
98
|
+
a1 = all_packages.to_a
|
99
|
+
a2 = all_packages.to_a
|
100
|
+
a1.each_with_index do |pkg, i|
|
101
|
+
expect(pkg).to be(a2[i])
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Resync
|
4
|
+
class Client
|
5
|
+
module Mixins
|
6
|
+
describe ListIndex do
|
7
|
+
before(:each) do
|
8
|
+
@helper = instance_double(Client::HTTPHelper)
|
9
|
+
@client = Client.new(helper: @helper)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#all_resources' do
|
13
|
+
it 'flattens the child resourcelists' do
|
14
|
+
index_uri = URI('http://example.com/resource-list-index.xml')
|
15
|
+
index_data = File.read('spec/data/examples/resource-list-index.xml')
|
16
|
+
expect(@helper).to receive(:fetch).with(uri: index_uri).and_return(index_data)
|
17
|
+
|
18
|
+
list_1_uri = URI('http://example.com/resourcelist1.xml')
|
19
|
+
list_1_data = File.read('spec/data/examples/resource-list-1.xml')
|
20
|
+
expect(@helper).to receive(:fetch).with(uri: list_1_uri).once.and_return(list_1_data)
|
21
|
+
|
22
|
+
list_1_uri = URI('http://example.com/resourcelist2.xml')
|
23
|
+
list_1_data = File.read('spec/data/examples/resource-list-2.xml')
|
24
|
+
expect(@helper).to receive(:fetch).with(uri: list_1_uri).once.and_return(list_1_data)
|
25
|
+
|
26
|
+
list_1_uri = URI('http://example.com/resourcelist3.xml')
|
27
|
+
list_1_data = File.read('spec/data/examples/resource-list-3.xml')
|
28
|
+
expect(@helper).to receive(:fetch).with(uri: list_1_uri).once.and_return(list_1_data)
|
29
|
+
|
30
|
+
index = @client.get_and_parse(index_uri)
|
31
|
+
all_resources = index.all_resources.to_a
|
32
|
+
expect(all_resources.size).to eq(6)
|
33
|
+
all_resources.each_with_index do |r, i|
|
34
|
+
expected_uri = URI("http://example.com/res#{i + 1}")
|
35
|
+
expect(r.uri).to eq(expected_uri)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is lazy enough not to download anything till it \'s iterated ' do
|
40
|
+
index_uri = URI('http://example.com/resource-list-index.xml')
|
41
|
+
index_data = File.read('spec/data/examples/resource-list-index.xml')
|
42
|
+
expect(@helper).to receive(:fetch).with(uri: index_uri).and_return(index_data)
|
43
|
+
|
44
|
+
list_1_uri = URI('http://example.com/resourcelist1.xml')
|
45
|
+
expect(@helper).not_to receive(:fetch).with(uri: list_1_uri)
|
46
|
+
|
47
|
+
list_1_uri = URI('http://example.com/resourcelist2.xml')
|
48
|
+
expect(@helper).not_to receive(:fetch).with(uri: list_1_uri)
|
49
|
+
|
50
|
+
list_1_uri = URI('http://example.com/resourcelist3.xml')
|
51
|
+
expect(@helper).not_to receive(:fetch).with(uri: list_1_uri)
|
52
|
+
|
53
|
+
index = @client.get_and_parse(index_uri)
|
54
|
+
index.all_resources
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'is lazy enough not to download resources it doesn\'t need' do
|
58
|
+
index_uri = URI('http://example.com/resource-list-index.xml')
|
59
|
+
index_data = File.read('spec/data/examples/resource-list-index.xml')
|
60
|
+
expect(@helper).to receive(:fetch).with(uri: index_uri).and_return(index_data)
|
61
|
+
|
62
|
+
list_1_uri = URI('http://example.com/resourcelist1.xml')
|
63
|
+
list_1_data = File.read('spec/data/examples/resource-list-1.xml')
|
64
|
+
expect(@helper).to receive(:fetch).with(uri: list_1_uri).once.and_return(list_1_data)
|
65
|
+
|
66
|
+
list_1_uri = URI('http://example.com/resourcelist2.xml')
|
67
|
+
list_1_data = File.read('spec/data/examples/resource-list-2.xml')
|
68
|
+
expect(@helper).to receive(:fetch).with(uri: list_1_uri).once.and_return(list_1_data)
|
69
|
+
|
70
|
+
list_1_uri = URI('http://example.com/resourcelist3.xml')
|
71
|
+
expect(@helper).not_to receive(:fetch).with(uri: list_1_uri)
|
72
|
+
|
73
|
+
index = @client.get_and_parse(index_uri)
|
74
|
+
index.all_resources.each_with_index do |_, i|
|
75
|
+
break if i >= 3
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'caches downloaded resources' do
|
80
|
+
index_uri = URI('http://example.com/resource-list-index.xml')
|
81
|
+
index_data = File.read('spec/data/examples/resource-list-index.xml')
|
82
|
+
expect(@helper).to receive(:fetch).with(uri: index_uri).and_return(index_data)
|
83
|
+
|
84
|
+
list_1_uri = URI('http://example.com/resourcelist1.xml')
|
85
|
+
list_1_data = File.read('spec/data/examples/resource-list-1.xml')
|
86
|
+
expect(@helper).to receive(:fetch).with(uri: list_1_uri).once.and_return(list_1_data)
|
87
|
+
|
88
|
+
list_1_uri = URI('http://example.com/resourcelist2.xml')
|
89
|
+
list_1_data = File.read('spec/data/examples/resource-list-2.xml')
|
90
|
+
expect(@helper).to receive(:fetch).with(uri: list_1_uri).once.and_return(list_1_data)
|
91
|
+
|
92
|
+
list_1_uri = URI('http://example.com/resourcelist3.xml')
|
93
|
+
list_1_data = File.read('spec/data/examples/resource-list-3.xml')
|
94
|
+
expect(@helper).to receive(:fetch).with(uri: list_1_uri).once.and_return(list_1_data)
|
95
|
+
|
96
|
+
index = @client.get_and_parse(index_uri)
|
97
|
+
a1 = index.all_resources.to_a
|
98
|
+
a2 = index.all_resources.to_a
|
99
|
+
a1.each_with_index do |r, i|
|
100
|
+
expect(r).to be(a2[i])
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -29,6 +29,30 @@ module Resync
|
|
29
29
|
expect(zip_packages[1]).to be(zip_package)
|
30
30
|
end
|
31
31
|
|
32
|
+
it 'flatmaps' do
|
33
|
+
resources = Array.new(6) { |i| Resource.new(uri: "http://example.org/res#{i}") }
|
34
|
+
all_packages = Array.new(6) do |i|
|
35
|
+
zip_package = instance_double(ZipPackage)
|
36
|
+
expect(resources[i]).to receive(:zip_package).once.and_return(zip_package)
|
37
|
+
zip_package
|
38
|
+
end
|
39
|
+
|
40
|
+
zip_packages_1 = ZipPackages.new(resources[0, 3])
|
41
|
+
zip_packages_2 = ZipPackages.new(resources[3, 3])
|
42
|
+
|
43
|
+
zrl1 = instance_double(Resync::Client::Mixins::Dump)
|
44
|
+
expect(zrl1).to receive(:zip_packages).twice.and_return(zip_packages_1)
|
45
|
+
|
46
|
+
zrl2 = instance_double(Resync::Client::Mixins::Dump)
|
47
|
+
expect(zrl2).to receive(:zip_packages).twice.and_return(zip_packages_2)
|
48
|
+
|
49
|
+
flat_mapped = [zrl1, zrl2].flat_map(&:zip_packages)
|
50
|
+
expect(flat_mapped).to eq(all_packages)
|
51
|
+
|
52
|
+
lazy_flat_mapped = [zrl1, zrl2].lazy.flat_map(&:zip_packages).to_a
|
53
|
+
expect(lazy_flat_mapped).to eq(all_packages)
|
54
|
+
end
|
55
|
+
|
32
56
|
it 'supports lazy iteration' do
|
33
57
|
manifests = Array.new(3) { instance_double(ChangeDumpManifest) }
|
34
58
|
all_packages = Array.new(3) do |index|
|
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.2.
|
4
|
+
version: 0.2.4
|
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-
|
11
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: resync
|
@@ -163,19 +163,20 @@ files:
|
|
163
163
|
- lib/resync/client/http_helper.rb
|
164
164
|
- lib/resync/client/mixins.rb
|
165
165
|
- lib/resync/client/mixins/bitstream_resource.rb
|
166
|
-
- lib/resync/client/mixins/bitstream_resource_list.rb
|
167
166
|
- lib/resync/client/mixins/client_delegator.rb
|
168
167
|
- lib/resync/client/mixins/downloadable.rb
|
168
|
+
- lib/resync/client/mixins/dump.rb
|
169
|
+
- lib/resync/client/mixins/dump_index.rb
|
170
|
+
- lib/resync/client/mixins/dump_manifest.rb
|
169
171
|
- lib/resync/client/mixins/link_client_delegate.rb
|
172
|
+
- lib/resync/client/mixins/list_index.rb
|
170
173
|
- lib/resync/client/mixins/resource_client_delegate.rb
|
171
174
|
- lib/resync/client/mixins/zipped_resource.rb
|
172
|
-
- lib/resync/client/mixins/zipped_resource_list.rb
|
173
175
|
- lib/resync/client/version.rb
|
174
176
|
- lib/resync/client/zip.rb
|
175
177
|
- lib/resync/client/zip/bitstream.rb
|
176
178
|
- lib/resync/client/zip/zip_package.rb
|
177
179
|
- lib/resync/client/zip/zip_packages.rb
|
178
|
-
- lib/resync/extensions.rb
|
179
180
|
- resync-client.gemspec
|
180
181
|
- spec/acceptance/example_spec.rb
|
181
182
|
- spec/data/examples/capability-list.xml
|
@@ -185,6 +186,9 @@ files:
|
|
185
186
|
- spec/data/examples/change-list.xml
|
186
187
|
- spec/data/examples/resource-dump-manifest.xml
|
187
188
|
- spec/data/examples/resource-dump.xml
|
189
|
+
- spec/data/examples/resource-list-1.xml
|
190
|
+
- spec/data/examples/resource-list-2.xml
|
191
|
+
- spec/data/examples/resource-list-3.xml
|
188
192
|
- spec/data/examples/resource-list-index.xml
|
189
193
|
- spec/data/examples/resource-list.xml
|
190
194
|
- spec/data/examples/source-description.xml
|
@@ -203,11 +207,13 @@ files:
|
|
203
207
|
- spec/todo.rb
|
204
208
|
- spec/unit/resync/client/bitstream_spec.rb
|
205
209
|
- spec/unit/resync/client/client_spec.rb
|
210
|
+
- spec/unit/resync/client/dump_index_spec.rb
|
211
|
+
- spec/unit/resync/client/dump_spec.rb
|
206
212
|
- spec/unit/resync/client/extensions_spec.rb
|
207
213
|
- spec/unit/resync/client/http_helper_spec.rb
|
214
|
+
- spec/unit/resync/client/list_index_spec.rb
|
208
215
|
- spec/unit/resync/client/zip_package_spec.rb
|
209
216
|
- spec/unit/resync/client/zip_packages_spec.rb
|
210
|
-
- spec/unit/resync/client/zipped_resource_list_spec.rb
|
211
217
|
homepage: http://github.com/dmolesUC3/resync-client
|
212
218
|
licenses:
|
213
219
|
- MIT
|
@@ -241,6 +247,9 @@ test_files:
|
|
241
247
|
- spec/data/examples/change-list.xml
|
242
248
|
- spec/data/examples/resource-dump-manifest.xml
|
243
249
|
- spec/data/examples/resource-dump.xml
|
250
|
+
- spec/data/examples/resource-list-1.xml
|
251
|
+
- spec/data/examples/resource-list-2.xml
|
252
|
+
- spec/data/examples/resource-list-3.xml
|
244
253
|
- spec/data/examples/resource-list-index.xml
|
245
254
|
- spec/data/examples/resource-list.xml
|
246
255
|
- spec/data/examples/source-description.xml
|
@@ -259,9 +268,11 @@ test_files:
|
|
259
268
|
- spec/todo.rb
|
260
269
|
- spec/unit/resync/client/bitstream_spec.rb
|
261
270
|
- spec/unit/resync/client/client_spec.rb
|
271
|
+
- spec/unit/resync/client/dump_index_spec.rb
|
272
|
+
- spec/unit/resync/client/dump_spec.rb
|
262
273
|
- spec/unit/resync/client/extensions_spec.rb
|
263
274
|
- spec/unit/resync/client/http_helper_spec.rb
|
275
|
+
- spec/unit/resync/client/list_index_spec.rb
|
264
276
|
- spec/unit/resync/client/zip_package_spec.rb
|
265
277
|
- spec/unit/resync/client/zip_packages_spec.rb
|
266
|
-
- spec/unit/resync/client/zipped_resource_list_spec.rb
|
267
278
|
has_rdoc:
|
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative '../zip'
|
2
|
-
require_relative 'bitstream_resource'
|
3
|
-
|
4
|
-
# A list of resources within a single zipped bitstream package, e.g. as provided
|
5
|
-
# by the package manifest.
|
6
|
-
#
|
7
|
-
# @!attribute [rw] zip_package
|
8
|
-
# @return [ZipPackage] the package.
|
9
|
-
module Resync
|
10
|
-
class Client
|
11
|
-
module Mixins
|
12
|
-
module BitstreamResourceList
|
13
|
-
attr_accessor :zip_package
|
14
|
-
|
15
|
-
# Makes each provided resource a {BitstreamResource}
|
16
|
-
# @param value [Array<Resource>] the resources for this list
|
17
|
-
def resources=(value)
|
18
|
-
super
|
19
|
-
resources.each do |r|
|
20
|
-
class << r
|
21
|
-
prepend BitstreamResource
|
22
|
-
end
|
23
|
-
r.zip_package_delegate = self
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/lib/resync/extensions.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'resync'
|
2
|
-
require_relative 'client/mixins'
|
3
|
-
|
4
|
-
module Resync
|
5
|
-
class Link
|
6
|
-
prepend Client::Mixins::Downloadable
|
7
|
-
end
|
8
|
-
|
9
|
-
class Augmented
|
10
|
-
prepend Client::Mixins::LinkClientDelegate
|
11
|
-
end
|
12
|
-
|
13
|
-
class Resource
|
14
|
-
prepend Client::Mixins::Downloadable
|
15
|
-
end
|
16
|
-
|
17
|
-
class BaseResourceList
|
18
|
-
prepend Client::Mixins::ResourceClientDelegate
|
19
|
-
end
|
20
|
-
|
21
|
-
class ResourceDump
|
22
|
-
prepend Client::Mixins::ZippedResourceList
|
23
|
-
end
|
24
|
-
|
25
|
-
class ChangeDump
|
26
|
-
prepend Client::Mixins::ZippedResourceList
|
27
|
-
end
|
28
|
-
|
29
|
-
class ResourceDumpManifest
|
30
|
-
prepend Client::Mixins::BitstreamResourceList
|
31
|
-
end
|
32
|
-
|
33
|
-
class ChangeDumpManifest
|
34
|
-
prepend Client::Mixins::BitstreamResourceList
|
35
|
-
end
|
36
|
-
end
|