arstotzka 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +2 -2
- data/Dockerfile +1 -1
- data/README.md +2 -1
- data/arstotzka.gemspec +1 -1
- data/lib/arstotzka/config.rb +7 -2
- data/lib/arstotzka/version.rb +1 -1
- data/lib/arstotzka/wrapper.rb +12 -0
- data/spec/integration/yard/arstotzka/config_spec.rb +2 -1
- data/spec/lib/arstotzka/config_spec.rb +5 -2
- data/spec/lib/arstotzka/wrapper_spec.rb +76 -2
- data/spec/support/models/arstotzka/fetcher/dummy.rb +4 -0
- data/spec/support/models/person.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 33a840eef86f6e4e433a4ecfc5a1744b29c6c2e5a632d9b700e907d45ac2b9cf
|
|
4
|
+
data.tar.gz: cd4ca82455ddd2b49209becdb97380658852214c70f10de0bb13063cdb37c8b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0dc3f7d36565b7cd3853a44d53cedc140e7ffcddfe59815650cced1172b0654e5136e04cbc4105b353282f591ed2d331fcbc8018c0e1994b93167eac231716de
|
|
7
|
+
data.tar.gz: 3495dc73ad34c2d2a78d581212ee993c12e061a9ba58b39f015bcf515ba6b849aff4ce9076cb91ec938cfad485f443a7281f26b2db37c2a3b12616f08be4cec8
|
data/.circleci/config.yml
CHANGED
|
@@ -18,7 +18,7 @@ workflows:
|
|
|
18
18
|
jobs:
|
|
19
19
|
test:
|
|
20
20
|
docker:
|
|
21
|
-
- image: darthjee/circleci_ruby_gems:0.5.
|
|
21
|
+
- image: darthjee/circleci_ruby_gems:0.5.4
|
|
22
22
|
environment:
|
|
23
23
|
PROJECT: arstotzka
|
|
24
24
|
steps:
|
|
@@ -52,7 +52,7 @@ jobs:
|
|
|
52
52
|
command: check_specs
|
|
53
53
|
build-and-release:
|
|
54
54
|
docker:
|
|
55
|
-
- image: darthjee/circleci_ruby_gems:0.5.
|
|
55
|
+
- image: darthjee/circleci_ruby_gems:0.5.4
|
|
56
56
|
environment:
|
|
57
57
|
PROJECT: arstotzka
|
|
58
58
|
steps:
|
data/Dockerfile
CHANGED
data/README.md
CHANGED
|
@@ -21,7 +21,7 @@ JSON keys)
|
|
|
21
21
|
|
|
22
22
|
Yard Documentation
|
|
23
23
|
-------------------
|
|
24
|
-
[https://www.rubydoc.info/gems/arstotzka/1.
|
|
24
|
+
[https://www.rubydoc.info/gems/arstotzka/1.6.0](https://www.rubydoc.info/gems/arstotzka/1.6.0)
|
|
25
25
|
|
|
26
26
|
Instalation
|
|
27
27
|
---------------
|
|
@@ -114,6 +114,7 @@ Options
|
|
|
114
114
|
- json: Method that contains the hash to be parsed (`:json` by default)
|
|
115
115
|
- path: Path where to find the sub hash that contains the key (empty by default)
|
|
116
116
|
- type: Type that the value must be cast into ([TypeCast](#typecast))
|
|
117
|
+
- before: method to be ran on result before any wrapping
|
|
117
118
|
|
|
118
119
|
## TypeCast
|
|
119
120
|
The type casting, when the option `type` is passed, is done through the `Arstotzka::TypeCast` which can
|
data/arstotzka.gemspec
CHANGED
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
|
19
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
20
20
|
gem.require_paths = ['lib']
|
|
21
21
|
|
|
22
|
-
gem.add_runtime_dependency 'activesupport', '~> 5.2.
|
|
22
|
+
gem.add_runtime_dependency 'activesupport', '~> 5.2.4.3'
|
|
23
23
|
gem.add_runtime_dependency 'sinclair', '>= 1.6.5'
|
|
24
24
|
|
|
25
25
|
gem.add_development_dependency 'bundler', '1.16.1'
|
data/lib/arstotzka/config.rb
CHANGED
|
@@ -57,7 +57,8 @@ module Arstotzka
|
|
|
57
57
|
flatten: false,
|
|
58
58
|
json: :json,
|
|
59
59
|
klass: nil,
|
|
60
|
-
type: :none
|
|
60
|
+
type: :none,
|
|
61
|
+
before: nil
|
|
61
62
|
}.freeze
|
|
62
63
|
|
|
63
64
|
add_configs DEFAULT_CONFIGS
|
|
@@ -93,7 +94,11 @@ module Arstotzka
|
|
|
93
94
|
# # flatten: false,
|
|
94
95
|
# # json: :json,
|
|
95
96
|
# # klass: Person,
|
|
96
|
-
# # type: :none
|
|
97
|
+
# # type: :none,
|
|
98
|
+
# # full_path: nil,
|
|
99
|
+
# # key: nil,
|
|
100
|
+
# # instance: nil,
|
|
101
|
+
# # befor: nil
|
|
97
102
|
# # }
|
|
98
103
|
def options(options_hash = {})
|
|
99
104
|
Options.new(
|
data/lib/arstotzka/version.rb
CHANGED
data/lib/arstotzka/wrapper.rb
CHANGED
|
@@ -75,6 +75,7 @@ module Arstotzka
|
|
|
75
75
|
#
|
|
76
76
|
# @return [Object]
|
|
77
77
|
def wrap_element(value)
|
|
78
|
+
value = apply_before(value)
|
|
78
79
|
value = cast(value)
|
|
79
80
|
return if value.nil?
|
|
80
81
|
|
|
@@ -83,6 +84,17 @@ module Arstotzka
|
|
|
83
84
|
after(value)
|
|
84
85
|
end
|
|
85
86
|
|
|
87
|
+
# @private
|
|
88
|
+
#
|
|
89
|
+
# Apply before option call
|
|
90
|
+
#
|
|
91
|
+
# @return [Object]
|
|
92
|
+
def apply_before(value)
|
|
93
|
+
return value unless options.before
|
|
94
|
+
|
|
95
|
+
options.instance.send(options.before, value)
|
|
96
|
+
end
|
|
97
|
+
|
|
86
98
|
# @private
|
|
87
99
|
#
|
|
88
100
|
# Wraps each element of the array
|
|
@@ -44,7 +44,8 @@ describe Arstotzka::Config do
|
|
|
44
44
|
full_path: nil,
|
|
45
45
|
key: nil,
|
|
46
46
|
instance: nil,
|
|
47
|
-
path: nil
|
|
47
|
+
path: nil,
|
|
48
|
+
before: :before_action
|
|
48
49
|
}
|
|
49
50
|
end
|
|
50
51
|
|
|
@@ -60,6 +61,7 @@ describe Arstotzka::Config do
|
|
|
60
61
|
json :@hash
|
|
61
62
|
klass Account
|
|
62
63
|
type :string
|
|
64
|
+
before :before_action
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
|
|
@@ -89,7 +91,8 @@ describe Arstotzka::Config do
|
|
|
89
91
|
full_path: nil,
|
|
90
92
|
key: nil,
|
|
91
93
|
instance: nil,
|
|
92
|
-
path: nil
|
|
94
|
+
path: nil,
|
|
95
|
+
before: nil
|
|
93
96
|
}
|
|
94
97
|
end
|
|
95
98
|
|
|
@@ -8,7 +8,7 @@ describe Arstotzka::Wrapper do
|
|
|
8
8
|
let(:hash) { { a: 1 } }
|
|
9
9
|
|
|
10
10
|
describe '#wrap' do
|
|
11
|
-
let(:value)
|
|
11
|
+
let(:value) { hash }
|
|
12
12
|
let(:result) { subject.wrap(value) }
|
|
13
13
|
|
|
14
14
|
context 'with default options' do
|
|
@@ -25,7 +25,7 @@ describe Arstotzka::Wrapper do
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
context 'with klass
|
|
28
|
+
context 'with klass option' do
|
|
29
29
|
let(:options) { { klass: OpenStruct } }
|
|
30
30
|
|
|
31
31
|
it 'creates new instance from given class' do
|
|
@@ -49,6 +49,80 @@ describe Arstotzka::Wrapper do
|
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
+
context 'with klass and before option as symbol' do
|
|
53
|
+
let(:instance) { Arstotzka::Fetcher::Dummy.new(hash) }
|
|
54
|
+
let(:options) do
|
|
55
|
+
{ klass: OpenStruct, before: :ensure_age, instance: instance }
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
let(:hash) { { name: 'Joe' } }
|
|
59
|
+
|
|
60
|
+
it 'creates new instance from given class' do
|
|
61
|
+
expect(result).to be_a(OpenStruct)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
it 'uses the given value on object initialization' do
|
|
65
|
+
expect(result.name).to eq(hash[:name])
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'updates the hash before ' do
|
|
69
|
+
expect(result.age).to eq(10)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
context 'with an array as value' do
|
|
73
|
+
let(:value) { [hash] }
|
|
74
|
+
|
|
75
|
+
it 'returns an array' do
|
|
76
|
+
expect(result).to be_a(Array)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
it 'returns an array of objects of the given class' do
|
|
80
|
+
expect(result).to all(be_a(OpenStruct))
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'returns an array of objects of the initialized values' do
|
|
84
|
+
expect(result.map(&:name)).to all(eq(hash[:name]))
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'updates the hash before ' do
|
|
88
|
+
expect(result.map(&:age)).to all(eq(10))
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
context 'with after_each option as symbol' do
|
|
94
|
+
let(:instance) { Group.new(hash) }
|
|
95
|
+
let(:options) do
|
|
96
|
+
{ after_each: :create_person, instance: instance }
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
let(:hash) { 'Fred' }
|
|
100
|
+
|
|
101
|
+
it 'Runs before each on each element' do
|
|
102
|
+
expect(result).to be_a(Person)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
it 'uses the given value on object initialization' do
|
|
106
|
+
expect(result.name).to eq('Fred')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context 'when hash is an array' do
|
|
110
|
+
let(:hash) { %w[Wilma Fred Dino] }
|
|
111
|
+
|
|
112
|
+
it do
|
|
113
|
+
expect(result).to be_a(Array)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it 'Runs before each on each element' do
|
|
117
|
+
expect(result).to all(be_a(Person))
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'uses the given value on object initialization' do
|
|
121
|
+
expect(result.first.name).to eq('Wilma')
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
52
126
|
context 'with type otpion' do
|
|
53
127
|
let(:type) { :integer }
|
|
54
128
|
let(:value) { '1' }
|
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.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Darthjee
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-05-
|
|
11
|
+
date: 2020-05-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 5.2.
|
|
19
|
+
version: 5.2.4.3
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 5.2.
|
|
26
|
+
version: 5.2.4.3
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: sinclair
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|