arstotzka 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +1 -1
- data/Dockerfile +2 -4
- data/README.md +1 -1
- data/arstotzka.gemspec +1 -1
- data/config/yardstick.yml +10 -10
- data/lib/arstotzka.rb +12 -11
- data/lib/arstotzka/class_methods.rb +38 -2
- data/lib/arstotzka/crawler.rb +14 -21
- data/lib/arstotzka/fetcher.rb +24 -21
- data/lib/arstotzka/fetcher_builder.rb +167 -0
- data/lib/arstotzka/{builder.rb → method_builder.rb} +22 -49
- data/lib/arstotzka/options.rb +13 -6
- data/lib/arstotzka/reader.rb +4 -4
- data/lib/arstotzka/type_cast.rb +3 -2
- data/lib/arstotzka/version.rb +1 -1
- data/lib/arstotzka/wrapper.rb +1 -1
- data/spec/integration/yard/arstotzka/crawler_spec.rb +5 -4
- data/spec/integration/yard/arstotzka/fetcher_builder_spec.rb +91 -0
- data/spec/integration/yard/arstotzka/fetcher_spec.rb +2 -2
- data/spec/integration/yard/arstotzka/{builder_spec.rb → method_builder_spec.rb} +3 -2
- data/spec/integration/yard/arstotzka/reader_spec.rb +2 -1
- data/spec/lib/arstotzka/crawler_spec.rb +3 -2
- data/spec/lib/arstotzka/fetcher_builder_spec.rb +30 -0
- data/spec/lib/arstotzka/fetcher_spec.rb +13 -13
- data/spec/lib/arstotzka/{builder_spec.rb → method_builder_spec.rb} +2 -1
- data/spec/lib/arstotzka/options_spec.rb +83 -0
- data/spec/lib/arstotzka/reader_spec.rb +2 -1
- data/spec/support/models/account.rb +6 -0
- data/spec/support/models/arstotzka/fetcher/dummy.rb +7 -0
- data/spec/support/models/my_model.rb +2 -0
- data/spec/support/models/star.rb +13 -2
- data/spec/support/models/star_gazer.rb +6 -0
- metadata +15 -10
@@ -4,17 +4,16 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Arstotzka::Fetcher do
|
6
6
|
subject(:fetcher) do
|
7
|
-
described_class.new
|
7
|
+
described_class.new instance, options
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:
|
11
|
-
let(:instance) { Arstotzka::Fetcher::Dummy.new }
|
10
|
+
let(:instance) { Arstotzka::Fetcher::Dummy.new(json) }
|
12
11
|
let(:json) { load_json_fixture_file('arstotzka.json') }
|
13
12
|
let(:value) { fetcher.fetch }
|
14
13
|
|
15
14
|
context 'when fetching with no options' do
|
16
|
-
let(:options) { {} }
|
17
|
-
let(:
|
15
|
+
let(:options) { { key: key } }
|
16
|
+
let(:key) { 'id' }
|
18
17
|
|
19
18
|
it 'retrieves attribute from base json' do
|
20
19
|
expect(value).to eq(json['id'])
|
@@ -45,17 +44,18 @@ describe Arstotzka::Fetcher do
|
|
45
44
|
end
|
46
45
|
|
47
46
|
describe 'flatten options' do
|
48
|
-
let(:json) {
|
47
|
+
let(:json) { { value: value } }
|
48
|
+
let(:value) { [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] }
|
49
49
|
|
50
50
|
context 'when flatten option is true' do
|
51
|
-
let(:options) { { flatten: true } }
|
51
|
+
let(:options) { { flatten: true, key: :value } }
|
52
52
|
|
53
53
|
it 'returns the fetched value flattened' do
|
54
54
|
expect(fetcher.fetch).to eq((1..8).to_a)
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'when value is not an array' do
|
58
|
-
let(:
|
58
|
+
let(:value) { 1 }
|
59
59
|
|
60
60
|
it 'returns the fetched value flattened' do
|
61
61
|
expect(fetcher.fetch).to eq(1)
|
@@ -64,18 +64,18 @@ describe Arstotzka::Fetcher do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'when flatten option is false' do
|
67
|
-
let(:options) { { flatten: false } }
|
67
|
+
let(:options) { { flatten: false, key: :value } }
|
68
68
|
|
69
69
|
it 'returns the fetched value non flattened' do
|
70
|
-
expect(fetcher.fetch).to eq(
|
70
|
+
expect(fetcher.fetch).to eq(value)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
describe 'after option' do
|
76
76
|
let(:instance) { MyParser.new(json) }
|
77
|
-
let(:json) { [100, 250, -25] }
|
78
|
-
let(:options) { { after: :sum } }
|
77
|
+
let(:json) { { value: [100, 250, -25] } }
|
78
|
+
let(:options) { { after: :sum, key: :value } }
|
79
79
|
|
80
80
|
it 'applies after call ' do
|
81
81
|
expect(fetcher.fetch).to eq(325)
|
@@ -86,7 +86,7 @@ describe Arstotzka::Fetcher do
|
|
86
86
|
let(:path) { 'name' }
|
87
87
|
let(:name) { 'Robert' }
|
88
88
|
let(:json) { { name: name } }
|
89
|
-
let(:options) { { klass: wrapper } }
|
89
|
+
let(:options) { { klass: wrapper, path: path } }
|
90
90
|
let(:wrapper) { Person }
|
91
91
|
|
92
92
|
it 'wraps the result in an object' do
|
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
describe Arstotzka::
|
5
|
+
describe Arstotzka::MethodBuilder do
|
6
6
|
subject(:builder) do
|
7
7
|
described_class.new(attr_names, klass, **full_options)
|
8
8
|
end
|
9
9
|
|
10
10
|
let(:klass) do
|
11
11
|
Class.new.tap do |c|
|
12
|
+
c.send(:include, Arstotzka)
|
12
13
|
c.send(:attr_reader, :json)
|
13
14
|
c.send(:define_method, :initialize) do |json = {}|
|
14
15
|
@json = json
|
@@ -205,4 +205,87 @@ describe Arstotzka::Options do
|
|
205
205
|
expect(options.merge(default: 10).json).to eq(:hash)
|
206
206
|
end
|
207
207
|
end
|
208
|
+
|
209
|
+
describe '#keys' do
|
210
|
+
let(:options_hash) { { path: path, key: key, full_path: full_path } }
|
211
|
+
let(:key) { :id }
|
212
|
+
let(:path) { nil }
|
213
|
+
let(:full_path) { nil }
|
214
|
+
|
215
|
+
context 'when full_path is nil' do
|
216
|
+
context 'when path is nil' do
|
217
|
+
it 'returns only the key' do
|
218
|
+
expect(options.keys).to eq(['id'])
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context 'when path is empty' do
|
223
|
+
let(:path) { '' }
|
224
|
+
|
225
|
+
it 'returns only the key' do
|
226
|
+
expect(options.keys).to eq(['id'])
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when path is not empty' do
|
231
|
+
let(:path) { 'account.person' }
|
232
|
+
|
233
|
+
it 'returns the path splitted and the key' do
|
234
|
+
expect(options.keys).to eq(%w[account person id])
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'when full_path is empty' do
|
240
|
+
let(:full_path) { '' }
|
241
|
+
|
242
|
+
context 'when path is nil' do
|
243
|
+
it 'returns empty array' do
|
244
|
+
expect(options.keys).to eq([])
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context 'when path is empty' do
|
249
|
+
let(:path) { '' }
|
250
|
+
|
251
|
+
it 'returns empty array' do
|
252
|
+
expect(options.keys).to eq([])
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'when path is not empty' do
|
257
|
+
let(:path) { 'account.person' }
|
258
|
+
|
259
|
+
it 'returns empty array' do
|
260
|
+
expect(options.keys).to eq([])
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'when full_path is not empty' do
|
266
|
+
let(:full_path) { 'account.person_id' }
|
267
|
+
|
268
|
+
context 'when path is nil' do
|
269
|
+
it 'returns splitted full path' do
|
270
|
+
expect(options.keys).to eq(%w[account person_id])
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
context 'when path is empty' do
|
275
|
+
let(:path) { '' }
|
276
|
+
|
277
|
+
it 'returns splitted full path' do
|
278
|
+
expect(options.keys).to eq(%w[account person_id])
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
context 'when path is not empty' do
|
283
|
+
let(:path) { 'account.person' }
|
284
|
+
|
285
|
+
it 'returns splitted full path' do
|
286
|
+
expect(options.keys).to eq(%w[account person_id])
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
208
291
|
end
|
@@ -24,10 +24,11 @@ end
|
|
24
24
|
|
25
25
|
describe Arstotzka::Reader do
|
26
26
|
subject(:reader) do
|
27
|
-
described_class.new(
|
27
|
+
described_class.new(full_path: full_path, case: case_type)
|
28
28
|
end
|
29
29
|
|
30
30
|
let(:keys) { %w[user full_name] }
|
31
|
+
let(:full_path) { keys.join('.') }
|
31
32
|
let(:json_file) { 'complete_person.json' }
|
32
33
|
let(:full_json) { load_json_fixture_file(json_file) }
|
33
34
|
let(:json) { full_json }
|
data/spec/support/models/star.rb
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Star
|
4
|
-
attr_reader :name
|
4
|
+
attr_reader :name, :color
|
5
5
|
|
6
|
-
def initialize(name:)
|
6
|
+
def initialize(name:, color: 'yellow')
|
7
7
|
@name = name
|
8
|
+
@color = color
|
9
|
+
end
|
10
|
+
|
11
|
+
def yellow?
|
12
|
+
color == 'yellow'
|
13
|
+
end
|
14
|
+
|
15
|
+
def ==(other)
|
16
|
+
return false unless other.is_a?(self.class)
|
17
|
+
other.color == color &&
|
18
|
+
other.name == name
|
8
19
|
end
|
9
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arstotzka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darthjee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.16.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.16.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry-nav
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -204,11 +204,12 @@ files:
|
|
204
204
|
- docker-compose.yml
|
205
205
|
- lib/arstotzka.rb
|
206
206
|
- lib/arstotzka/base.rb
|
207
|
-
- lib/arstotzka/builder.rb
|
208
207
|
- lib/arstotzka/class_methods.rb
|
209
208
|
- lib/arstotzka/crawler.rb
|
210
209
|
- lib/arstotzka/exception.rb
|
211
210
|
- lib/arstotzka/fetcher.rb
|
211
|
+
- lib/arstotzka/fetcher_builder.rb
|
212
|
+
- lib/arstotzka/method_builder.rb
|
212
213
|
- lib/arstotzka/options.rb
|
213
214
|
- lib/arstotzka/reader.rb
|
214
215
|
- lib/arstotzka/type_cast.rb
|
@@ -222,17 +223,19 @@ files:
|
|
222
223
|
- spec/fixtures/person.json
|
223
224
|
- spec/integration/readme/arstotzka_spec.rb
|
224
225
|
- spec/integration/readme/my_parser_spec.rb
|
225
|
-
- spec/integration/yard/arstotzka/builder_spec.rb
|
226
226
|
- spec/integration/yard/arstotzka/class_methods_spec.rb
|
227
227
|
- spec/integration/yard/arstotzka/crawler_spec.rb
|
228
|
+
- spec/integration/yard/arstotzka/fetcher_builder_spec.rb
|
228
229
|
- spec/integration/yard/arstotzka/fetcher_spec.rb
|
230
|
+
- spec/integration/yard/arstotzka/method_builder_spec.rb
|
229
231
|
- spec/integration/yard/arstotzka/reader_spec.rb
|
230
232
|
- spec/integration/yard/arstotzka/type_cast_spec.rb
|
231
233
|
- spec/integration/yard/arstotzka/wrapper_spec.rb
|
232
234
|
- spec/integration/yard/arstotzka_spec.rb
|
233
|
-
- spec/lib/arstotzka/builder_spec.rb
|
234
235
|
- spec/lib/arstotzka/crawler_spec.rb
|
236
|
+
- spec/lib/arstotzka/fetcher_builder_spec.rb
|
235
237
|
- spec/lib/arstotzka/fetcher_spec.rb
|
238
|
+
- spec/lib/arstotzka/method_builder_spec.rb
|
236
239
|
- spec/lib/arstotzka/options_spec.rb
|
237
240
|
- spec/lib/arstotzka/reader_spec.rb
|
238
241
|
- spec/lib/arstotzka/wrapper_spec.rb
|
@@ -279,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
282
|
version: '0'
|
280
283
|
requirements: []
|
281
284
|
rubyforge_project:
|
282
|
-
rubygems_version: 2.6
|
285
|
+
rubygems_version: 2.7.6
|
283
286
|
signing_key:
|
284
287
|
specification_version: 4
|
285
288
|
summary: Arstotzka
|
@@ -291,17 +294,19 @@ test_files:
|
|
291
294
|
- spec/fixtures/person.json
|
292
295
|
- spec/integration/readme/arstotzka_spec.rb
|
293
296
|
- spec/integration/readme/my_parser_spec.rb
|
294
|
-
- spec/integration/yard/arstotzka/builder_spec.rb
|
295
297
|
- spec/integration/yard/arstotzka/class_methods_spec.rb
|
296
298
|
- spec/integration/yard/arstotzka/crawler_spec.rb
|
299
|
+
- spec/integration/yard/arstotzka/fetcher_builder_spec.rb
|
297
300
|
- spec/integration/yard/arstotzka/fetcher_spec.rb
|
301
|
+
- spec/integration/yard/arstotzka/method_builder_spec.rb
|
298
302
|
- spec/integration/yard/arstotzka/reader_spec.rb
|
299
303
|
- spec/integration/yard/arstotzka/type_cast_spec.rb
|
300
304
|
- spec/integration/yard/arstotzka/wrapper_spec.rb
|
301
305
|
- spec/integration/yard/arstotzka_spec.rb
|
302
|
-
- spec/lib/arstotzka/builder_spec.rb
|
303
306
|
- spec/lib/arstotzka/crawler_spec.rb
|
307
|
+
- spec/lib/arstotzka/fetcher_builder_spec.rb
|
304
308
|
- spec/lib/arstotzka/fetcher_spec.rb
|
309
|
+
- spec/lib/arstotzka/method_builder_spec.rb
|
305
310
|
- spec/lib/arstotzka/options_spec.rb
|
306
311
|
- spec/lib/arstotzka/reader_spec.rb
|
307
312
|
- spec/lib/arstotzka/wrapper_spec.rb
|