arstotzka 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/README.md +1 -1
- data/config/yardstick.yml +0 -2
- data/lib/arstotzka/fetcher.rb +15 -1
- data/lib/arstotzka/version.rb +1 -1
- data/spec/lib/arstotzka/fetcher_spec.rb +42 -7
- data/spec/support/models/arstotzka/fetcher/class_variable.rb +11 -0
- data/spec/support/models/arstotzka/fetcher/hash_json.rb +15 -0
- data/spec/support/models/arstotzka/fetcher/no_accessor.rb +11 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1fd5f8ae512abca296de96373bd5f07d48b3172091437ccf50c5e47a2c5797a
|
4
|
+
data.tar.gz: 46ff041da66faf1bffe3fb0df64b71d268dd6e95dc2e9c43be2583eda005a924
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51f92382c369a3fdc44eaa02915f8837a3760f36b8a80fcb7b315ad2a11646cd9578e02a165d32eeebeb0114341865c540b8a5ba3cfd8025fc75382dca6aa63c
|
7
|
+
data.tar.gz: a2d26c467a2c768927a8cf18ade4682792522f5fb4e90332b8fd41e08b13516d5022a95b30da20f658f37924b2467494fe7cd8bb1109d092476279a7f1b77a94
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
data/config/yardstick.yml
CHANGED
@@ -23,7 +23,6 @@ rules:
|
|
23
23
|
- Arstotzka::Crawler#options
|
24
24
|
- Arstotzka::Fetcher#instance
|
25
25
|
- Arstotzka::Fetcher#options
|
26
|
-
- Arstotzka::Fetcher#hash
|
27
26
|
- Arstotzka::FetcherBuilder#options
|
28
27
|
- Arstotzka::MethodBuilder#attr_names
|
29
28
|
- Arstotzka::MethodBuilder#options
|
@@ -38,7 +37,6 @@ rules:
|
|
38
37
|
- Arstotzka::Crawler#options
|
39
38
|
- Arstotzka::Fetcher#instance
|
40
39
|
- Arstotzka::Fetcher#options
|
41
|
-
- Arstotzka::Fetcher#hash
|
42
40
|
- Arstotzka::FetcherBuilder#options
|
43
41
|
- Arstotzka::MethodBuilder#attr_names
|
44
42
|
- Arstotzka::MethodBuilder#options
|
data/lib/arstotzka/fetcher.rb
CHANGED
@@ -93,9 +93,23 @@ module Arstotzka
|
|
93
93
|
delegate :instance, :after, :flatten, to: :options
|
94
94
|
delegate :wrap, to: :wrapper
|
95
95
|
|
96
|
+
# @private
|
97
|
+
#
|
98
|
+
# Retrieves the hash to be crawled from the instance
|
99
|
+
#
|
100
|
+
# @return [Hash]
|
101
|
+
# rubocop:disable Metrics/AbcSize
|
96
102
|
def hash
|
97
|
-
@hash ||=
|
103
|
+
@hash ||= case options.json.to_s
|
104
|
+
when /^@@.*/
|
105
|
+
instance.class.class_variable_get(options.json)
|
106
|
+
when /^@.*/
|
107
|
+
then instance.instance_variable_get(options.json)
|
108
|
+
else
|
109
|
+
instance.send(options.json.to_s)
|
110
|
+
end
|
98
111
|
end
|
112
|
+
# rubocop:enable Metrics/AbcSize
|
99
113
|
|
100
114
|
# @private
|
101
115
|
#
|
data/lib/arstotzka/version.rb
CHANGED
@@ -7,13 +7,13 @@ describe Arstotzka::Fetcher do
|
|
7
7
|
described_class.new options
|
8
8
|
end
|
9
9
|
|
10
|
-
let(:options) { Arstotzka::Options.new(options_hash) }
|
10
|
+
let(:options) { Arstotzka::Options.new(options_hash.merge(instance: instance)) }
|
11
11
|
let(:instance) { Arstotzka::Fetcher::Dummy.new(json) }
|
12
12
|
let(:json) { load_json_fixture_file('arstotzka.json') }
|
13
13
|
let(:value) { fetcher.fetch }
|
14
14
|
|
15
15
|
context 'when fetching with no options' do
|
16
|
-
let(:options_hash) { {
|
16
|
+
let(:options_hash) { { key: key } }
|
17
17
|
let(:key) { 'id' }
|
18
18
|
|
19
19
|
it 'retrieves attribute from base json' do
|
@@ -50,7 +50,7 @@ describe Arstotzka::Fetcher do
|
|
50
50
|
|
51
51
|
context 'when flatten option is true' do
|
52
52
|
let(:options_hash) do
|
53
|
-
{
|
53
|
+
{ flatten: true, key: :value }
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'returns the fetched value flattened' do
|
@@ -68,7 +68,7 @@ describe Arstotzka::Fetcher do
|
|
68
68
|
|
69
69
|
context 'when flatten option is false' do
|
70
70
|
let(:options_hash) do
|
71
|
-
{
|
71
|
+
{ flatten: false, key: :value }
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'returns the fetched value non flattened' do
|
@@ -82,7 +82,7 @@ describe Arstotzka::Fetcher do
|
|
82
82
|
let(:json) { { value: [100, 250, -25] } }
|
83
83
|
|
84
84
|
let(:options_hash) do
|
85
|
-
{
|
85
|
+
{ after: :sum, key: :value }
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'applies after call ' do
|
@@ -97,7 +97,7 @@ describe Arstotzka::Fetcher do
|
|
97
97
|
let(:wrapper) { Person }
|
98
98
|
|
99
99
|
let(:options_hash) do
|
100
|
-
{
|
100
|
+
{ klass: wrapper, path: path }
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'wraps the result in an object' do
|
@@ -115,7 +115,6 @@ describe Arstotzka::Fetcher do
|
|
115
115
|
|
116
116
|
let(:options_hash) do
|
117
117
|
{
|
118
|
-
instance: instance,
|
119
118
|
full_path: full_path,
|
120
119
|
after_each: :create_person,
|
121
120
|
json: :@hash,
|
@@ -142,4 +141,40 @@ describe Arstotzka::Fetcher do
|
|
142
141
|
expect(fetcher.fetch).to all(be_a(Person))
|
143
142
|
end
|
144
143
|
end
|
144
|
+
|
145
|
+
describe 'json options' do
|
146
|
+
context 'when json is a method' do
|
147
|
+
let(:instance) { described_class::HashJson.new(hash) }
|
148
|
+
let(:hash) { { name: 'John Doe' } }
|
149
|
+
let(:options_hash) { { key: :name, json: :hash } }
|
150
|
+
|
151
|
+
it 'fetches hash from given method' do
|
152
|
+
expect(fetcher.fetch).to eq('John Doe')
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
context 'when json is an instance variable' do
|
157
|
+
let(:instance) { described_class::NoAccessor.new(hash) }
|
158
|
+
let(:hash) { { name: 'John Doe' } }
|
159
|
+
let(:options_hash) { { key: :name, json: :@hash } }
|
160
|
+
|
161
|
+
it 'fetches hash from given method' do
|
162
|
+
expect(fetcher.fetch).to eq('John Doe')
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context 'when json is an instance variable' do
|
167
|
+
let(:instance) { described_class::ClassVariable.new }
|
168
|
+
let(:hash) { { name: 'John Doe' } }
|
169
|
+
let(:options_hash) { { key: :name, json: :@@json } }
|
170
|
+
|
171
|
+
before do
|
172
|
+
described_class::ClassVariable.json = hash
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'fetches hash from given method' do
|
176
|
+
expect(fetcher.fetch).to eq('John Doe')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
145
180
|
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.2.
|
4
|
+
version: 1.2.2
|
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-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -247,7 +247,10 @@ files:
|
|
247
247
|
- spec/support/models/account.rb
|
248
248
|
- spec/support/models/application.rb
|
249
249
|
- spec/support/models/arstotzka/dummy.rb
|
250
|
+
- spec/support/models/arstotzka/fetcher/class_variable.rb
|
250
251
|
- spec/support/models/arstotzka/fetcher/dummy.rb
|
252
|
+
- spec/support/models/arstotzka/fetcher/hash_json.rb
|
253
|
+
- spec/support/models/arstotzka/fetcher/no_accessor.rb
|
251
254
|
- spec/support/models/arstotzka/type_cast.rb
|
252
255
|
- spec/support/models/arstotzka/wrapper/dummy.rb
|
253
256
|
- spec/support/models/bar.rb
|
@@ -327,7 +330,10 @@ test_files:
|
|
327
330
|
- spec/support/models/account.rb
|
328
331
|
- spec/support/models/application.rb
|
329
332
|
- spec/support/models/arstotzka/dummy.rb
|
333
|
+
- spec/support/models/arstotzka/fetcher/class_variable.rb
|
330
334
|
- spec/support/models/arstotzka/fetcher/dummy.rb
|
335
|
+
- spec/support/models/arstotzka/fetcher/hash_json.rb
|
336
|
+
- spec/support/models/arstotzka/fetcher/no_accessor.rb
|
331
337
|
- spec/support/models/arstotzka/type_cast.rb
|
332
338
|
- spec/support/models/arstotzka/wrapper/dummy.rb
|
333
339
|
- spec/support/models/bar.rb
|