resync 0.2.2 → 0.3.0

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: 30958a3d136a05395b75151c4396cc3a396d8dc0
4
- data.tar.gz: 1380f44a55d5305a1cf46988cbbc604f6672ad8f
3
+ metadata.gz: caaf4841db1483e0ee12a97a0c8feda2860ff307
4
+ data.tar.gz: 9042ffbe49a75096c1c8dca81aba9928180ba692
5
5
  SHA512:
6
- metadata.gz: 2262fa5a7028254fb4144772ec3cfe44982596a1cd69f8114afad7a4c9f1db5de0f2de0de7d0f25990ce6cf8c0a3d16fb35eaeb504c3f877fe6a6f2ab31660de
7
- data.tar.gz: 885631b5db2dae906e938f2a125c75f7f020d98dfbe2b964bd8ea6fe68ff3e3ba684137fd34ab2ff635ed94639e5c8b482eba457440de410d7830abc6d1c26a3
6
+ metadata.gz: 5d39cab4a6c3fc47078d1a8d5f9bcad996f82f07d11ca6906d801679e42452d64baeaf63c9c4e20d839618f00ddb6d15e4848f7993e9193bf1bcd2c309b5de27
7
+ data.tar.gz: c5f5cbc3479c46d519e0adfce8b7663e3fcd00a18775895059ab33c408b41ab9aca9138961e5a29a46a36701b17b0657cfc307a99c9204118cfefc3c4cfd5924
data/.travis.yml CHANGED
@@ -1,2 +1,6 @@
1
1
  language: ruby
2
2
 
3
+ addons:
4
+ code_climate:
5
+ repo_token: 7dbef7673e0f4ec8af5632f48fad7260cdaed36bb461620916ca08c988800af1
6
+
data/CHANGES.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.3.0
2
+
3
+ - Return simple arrays for resources, instead of fancy lazy enumerables
4
+
1
5
  ## 0.2.2
2
6
 
3
7
  - Added `#changes` method to `ChangeList` and `ChangeDumpManifest`, allowing filtering by change type and modified time
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # resync
1
+ # resync [![Build Status](https://travis-ci.org/dmolesUC3/resync.png?branch=master)](https://travis-ci.org/dmolesUC3/resync) [![Code Climate](https://codeclimate.com/github/dmolesUC3/resync.png)](https://codeclimate.com/github/dmolesUC3/resync) [![Inline docs](http://inch-ci.org/github/dmolesUC3/resync.png)](http://inch-ci.org/github/dmolesUC3/resync)
2
+
2
3
 
3
4
  A Ruby gem for working with the [ResourceSync](http://www.openarchives.org/rs/1.0/resourcesync) web synchronization framework.
4
5
 
@@ -90,3 +91,4 @@ When reading a ResourceSync document from XML and writing it back out, `<rs:ln>`
90
91
  #### Namespace weirdness
91
92
 
92
93
  The [XML::Mapping](https://github.com/multi-io/xml-mapping) library `resync` uses doesn't support namespaces, so namespace handling in `resync` is a bit hacky. In particular, you may see strange behavior when using `<rs:ln>`, `<rs:md>`, `<url>`, or `<sitemap>` tags outside the context of a `<urlset>`/`<sitemapindex>`.
94
+
@@ -12,7 +12,7 @@ module Resync
12
12
  # @param in_range [Range<Time>] the range of times to filter by
13
13
  # @param strict [Boolean] +true+ if resources without +from_time+ or +until_time+ should be
14
14
  # excluded, +false+ if they should be included.
15
- # @return [Enumerator::Lazy<Resource>] those change lists whose +from_time+ *or* +until_time+
15
+ # @return [Array<Resource>] those change lists whose +from_time+ *or* +until_time+
16
16
  # falls within +in_range+
17
17
  def change_lists(in_range:, strict: true)
18
18
  resources.select do |r|
@@ -6,7 +6,7 @@ module Resync
6
6
  # Filters the list of changes by change type, modification time, or both.
7
7
  # @param of_type [Types::Change] the change type
8
8
  # @param in_range [Range<Time>] the range of modification times
9
- # @return [Enumerator::Lazy<Resource>] the matching changes, or all changes
9
+ # @return [Array<Resource>] the matching changes, or all changes
10
10
  # if neither +of_type+ nor +in_range+ is specified.
11
11
  def changes(of_type: nil, in_range: nil)
12
12
  resources.select do |r|
@@ -9,7 +9,7 @@ module Resync
9
9
  # they represent (e.g. +resourcelist+, +changelist+).
10
10
  #
11
11
  # @!attribute [r] resources
12
- # @return [Util::IndexableLazy<Resource>] the +<url>+ or +<sitemap>+ elements contained in this list.
12
+ # @return [Array<Resource>] the +<url>+ or +<sitemap>+ elements contained in this list.
13
13
  class BaseResourceList < Augmented
14
14
  include ::XML::Mapping
15
15
 
@@ -40,7 +40,7 @@ module Resync
40
40
 
41
41
  # Sets the +resources+ list. +nil+ is treated as an empty list.
42
42
  def resources=(value)
43
- @resources = Util::IndexableLazy.new(value || [])
43
+ @resources = value || []
44
44
  end
45
45
 
46
46
  # Sets the metadata.
@@ -61,7 +61,7 @@ module Resync
61
61
 
62
62
  # Finds resources with the specified capability.
63
63
  # @param capability [String] the capability.
64
- # @return [Enumerator::Lazy<Resource>] those resources having that capability, or an empty array if none exist.
64
+ # @return [Array<Resource>] those resources having that capability, or an empty array if none exist.
65
65
  def resources_for(capability:)
66
66
  resources.select { |r| r.capability == capability }
67
67
  end
@@ -80,7 +80,7 @@ module Resync
80
80
  # @param time_range [Range[Time]] the range of acceptable times (inclusive or exclusive)
81
81
  # @param time_attr [Symbol] the time type to filter on: +:modified_time+, +:at_time+,
82
82
  # +:completed_time+, +:from_time+ or +:until_time+
83
- # @return [Enumerator::Lazy<Resource>] a lazy enumeration of the resources within the specified range.
83
+ # @return [Array<Resource>] a lazy enumeration of the resources within the specified range.
84
84
  def resources_in(time_range:, time_attr:)
85
85
  resources.select { |r| time_range.cover?(r.send(time_attr)) }
86
86
  end
@@ -1,4 +1,4 @@
1
1
  module Resync
2
2
  # The version of this gem.
3
- VERSION = '0.2.2'
3
+ VERSION = '0.3.0'
4
4
  end
data/lib/resync/xml.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'uri'
2
2
  require 'time'
3
3
  require 'xml/mapping'
4
+ require_relative 'types'
4
5
 
5
6
  module Resync
6
7
  # Helper methods and modules related to reading and writing XML.
@@ -106,10 +107,9 @@ module Resync
106
107
  ::XML::Mapping.add_node_class UriNode
107
108
 
108
109
  # ------------------------------------------------------------
109
- # Resync::Types::Change
110
+ # Resync::Types
110
111
 
111
- # Maps +Resync::Types::Change+ values.
112
- class ChangeNode < ::XML::Mapping::SingleAttributeNode
112
+ class EnumNode < ::XML::Mapping::SingleAttributeNode
113
113
  def initialize(*args)
114
114
  path, *args = super(*args)
115
115
  @path = ::XML::XXPath.new(path)
@@ -118,7 +118,8 @@ module Resync
118
118
 
119
119
  # Implements +::XML::Mapping::SingleAttributeNode#extract_attr_value+.
120
120
  def extract_attr_value(xml)
121
- Resync::Types::Change.parse(default_when_xpath_err { @path.first(xml).text })
121
+ enum_class = self.class::ENUM_CLASS
122
+ enum_class.parse(default_when_xpath_err { @path.first(xml).text })
122
123
  end
123
124
 
124
125
  # Implements +::XML::Mapping::SingleAttributeNode#set_attr_value+.
@@ -127,28 +128,22 @@ module Resync
127
128
  end
128
129
  end
129
130
 
131
+ # ------------------------------------------------------------
132
+ # Resync::Types::Change
133
+
134
+ # Maps +Resync::Types::Change+ values.
135
+ class ChangeNode < EnumNode
136
+ ENUM_CLASS = Resync::Types::Change
137
+ end
138
+
130
139
  ::XML::Mapping.add_node_class ChangeNode
131
140
 
132
141
  # ------------------------------------------------------------
133
142
  # Resync::Types::Changefreq
134
143
 
135
- # Maps +Resync::Types::Changefreq+ values.
136
- class ChangefreqNode < ::XML::Mapping::SingleAttributeNode
137
- def initialize(*args)
138
- path, *args = super(*args)
139
- @path = ::XML::XXPath.new(path)
140
- args
141
- end
142
-
143
- # Implements +::XML::Mapping::SingleAttributeNode#extract_attr_value+.
144
- def extract_attr_value(xml)
145
- Resync::Types::ChangeFrequency.parse(default_when_xpath_err { @path.first(xml).text })
146
- end
147
-
148
- # Implements +::XML::Mapping::SingleAttributeNode#set_attr_value+.
149
- def set_attr_value(xml, value)
150
- @path.first(xml, ensure_created: true).text = value.to_s
151
- end
144
+ # Maps +Resync::Types::ChangeFrequency+ values.
145
+ class ChangefreqNode < EnumNode
146
+ ENUM_CLASS = Resync::Types::ChangeFrequency
152
147
  end
153
148
 
154
149
  ::XML::Mapping.add_node_class ChangefreqNode
data/resync.gemspec CHANGED
@@ -33,4 +33,5 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'simplecov', '~> 0.9.2'
34
34
  spec.add_development_dependency 'simplecov-console', '~> 0.2.0'
35
35
  spec.add_development_dependency 'yard', '~> 0.8'
36
+ spec.add_development_dependency 'codeclimate-test-reporter'
36
37
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,12 @@
1
1
  # ------------------------------------------------------------
2
- # SimpleCov setup
2
+ # SimpleCov/CodeClimate setup
3
3
 
4
4
  if ENV['COVERAGE']
5
+ if ENV['CODECLIMATE_REPO_TOKEN']
6
+ require 'codeclimate-test-reporter'
7
+ CodeClimate::TestReporter.start
8
+ end
9
+
5
10
  require 'simplecov'
6
11
  require 'simplecov-console'
7
12
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
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-10 00:00:00.000000000 Z
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types
@@ -150,6 +150,20 @@ dependencies:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
152
  version: '0.8'
153
+ - !ruby/object:Gem::Dependency
154
+ name: codeclimate-test-reporter
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
153
167
  description: A Ruby gem for working with the ResourceSync web synchronization framework
154
168
  email:
155
169
  - david.moles@ucop.edu
@@ -194,7 +208,6 @@ files:
194
208
  - lib/resync/types/change.rb
195
209
  - lib/resync/types/change_frequency.rb
196
210
  - lib/resync/util.rb
197
- - lib/resync/util/indexable_lazy.rb
198
211
  - lib/resync/version.rb
199
212
  - lib/resync/xml.rb
200
213
  - lib/resync/xml_parser.rb
@@ -262,7 +275,6 @@ files:
262
275
  - spec/unit/resync/shared/sorted_list_examples.rb
263
276
  - spec/unit/resync/shared/uri_field_examples.rb
264
277
  - spec/unit/resync/source_description_spec.rb
265
- - spec/unit/resync/util/indexable_lazy_spec.rb
266
278
  - spec/unit/resync/xml/timenode_spec.rb
267
279
  - spec/unit/resync/xml/xml_spec.rb
268
280
  - spec/unit/resync/xml_parser_spec.rb
@@ -354,7 +366,6 @@ test_files:
354
366
  - spec/unit/resync/shared/sorted_list_examples.rb
355
367
  - spec/unit/resync/shared/uri_field_examples.rb
356
368
  - spec/unit/resync/source_description_spec.rb
357
- - spec/unit/resync/util/indexable_lazy_spec.rb
358
369
  - spec/unit/resync/xml/timenode_spec.rb
359
370
  - spec/unit/resync/xml/xml_spec.rb
360
371
  - spec/unit/resync/xml_parser_spec.rb
@@ -1,18 +0,0 @@
1
- require 'delegate'
2
-
3
- module Resync
4
- module Util
5
- class IndexableLazy < SimpleDelegator
6
-
7
- def initialize(array)
8
- super(array.lazy)
9
- @array = array
10
- end
11
-
12
- def [](key)
13
- @array[key]
14
- end
15
-
16
- end
17
- end
18
- end
@@ -1,133 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Resync
4
- module Util
5
- describe IndexableLazy do
6
-
7
- before(:each) do
8
- @size = 3
9
- @array = Array.new(@size) { instance_double(Object) }
10
- @lazy = IndexableLazy.new(@array)
11
- end
12
-
13
- describe '#size' do
14
- it 'returns the size of the underlying array' do
15
- expect(@lazy.size).to eq(@size)
16
- end
17
- end
18
-
19
- describe '#[]' do
20
- it 'is lazy' do
21
- expect(@array[0]).to receive(:to_s).and_return('0')
22
- expect(@array[1]).to receive(:to_s).and_return('1')
23
- expect(@array[2]).not_to receive(:to_s)
24
-
25
- (0...@lazy.size).each do |i|
26
- expect(@lazy[i]).to eq(@array[i])
27
- break if @lazy[i].to_s == '1'
28
- end
29
- end
30
- end
31
-
32
- describe '#each' do
33
- it 'is lazy' do
34
- expect(@array[0]).to receive(:to_s).and_return('0')
35
- expect(@array[1]).to receive(:to_s).and_return('1')
36
- expect(@array[2]).not_to receive(:to_s)
37
-
38
- @lazy.each do |v|
39
- break if v.to_s == '1'
40
- end
41
- end
42
- end
43
-
44
- describe '#each_with_index' do
45
- it 'is lazy' do
46
- expect(@array[0]).to receive(:to_s).and_return('0')
47
- expect(@array[1]).to receive(:to_s).and_return('1')
48
- expect(@array[2]).not_to receive(:to_s)
49
-
50
- @lazy.each_with_index do |v, i|
51
- break if v.to_s == '1' || i > 1
52
- end
53
- end
54
- end
55
-
56
- describe '#each_with_object' do
57
- it 'is lazy' do
58
- expect(@array[0]).to receive(:to_s).and_return('0')
59
- expect(@array[1]).to receive(:to_s).and_return('1')
60
- expect(@array[2]).not_to receive(:to_s)
61
-
62
- acc = []
63
- @lazy.each_with_object(acc) do |v, obj|
64
- obj << v.to_s
65
- break if obj[-1] == '1'
66
- end
67
- expect(acc).to eq(%w(0 1))
68
- end
69
- end
70
-
71
- describe '#find' do
72
- it 'is lazy' do
73
- expect(@array[0]).to receive(:to_s).and_return('0')
74
- expect(@array[1]).to receive(:to_s).and_return('1')
75
- expect(@array[2]).not_to receive(:to_s)
76
-
77
- expect(@lazy.find { |v| v.to_s == '1' }).to be(@array[1])
78
- end
79
- end
80
-
81
- describe '#find_index' do
82
- it 'is lazy' do
83
- expect(@array[0]).to receive(:to_s).and_return('0')
84
- expect(@array[1]).to receive(:to_s).and_return('1')
85
- expect(@array[2]).not_to receive(:to_s)
86
-
87
- expect(@lazy.find_index { |v| v.to_s == '1' }).to eq(1)
88
- end
89
- end
90
-
91
- describe '#take_while' do
92
- it 'is lazy' do
93
- expect(@array[0]).to receive(:to_s).and_return('0')
94
- expect(@array[1]).to receive(:to_s).and_return('1')
95
- expect(@array[2]).not_to receive(:to_s)
96
-
97
- expect(@lazy.take_while { |v| v.to_s == '0' }.to_a).to eq([@array[0]])
98
- end
99
- end
100
-
101
- describe '#map' do
102
- it 'is lazy' do
103
- expect(@array[0]).to receive(:to_s).and_return('0')
104
- expect(@array[1]).to receive(:to_s).and_return('1')
105
- expect(@array[2]).not_to receive(:to_s)
106
-
107
- mapped = @lazy.map(&:to_s)
108
- expect(mapped.take(2).to_a).to eq(%w(0 1))
109
- end
110
- end
111
-
112
- describe '#take' do
113
- it 'is lazy' do
114
- expect(@array[0]).to receive(:to_s).and_return('0')
115
- expect(@array[1]).to receive(:to_s).and_return('1')
116
- expect(@array[2]).not_to receive(:to_s)
117
-
118
- expect(@lazy.take(2).map(&:to_s).to_a).to eq(%w(0 1))
119
- end
120
- end
121
-
122
- describe '#select' do
123
- it 'is lazy' do
124
- expect(@array[0]).not_to receive(:to_s)
125
- expect(@array[1]).not_to receive(:to_s)
126
- expect(@array[2]).not_to receive(:to_s)
127
-
128
- @lazy.select(&:to_s)
129
- end
130
- end
131
- end
132
- end
133
- end