arstotzka 1.4.3 → 1.6.2

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
  SHA256:
3
- metadata.gz: cb00ef2078b07c28f27e67e9eac4503412f6f226fc680dc46ba7e1ca41d3a819
4
- data.tar.gz: 6c9deaed75e5f3bb5ee31f70fd756cd16b9a80633980b31dff386b380e622b57
3
+ metadata.gz: 700ed605bf255b877e119d9146b59f124672e6b9ca19aa193cba75d46e93f570
4
+ data.tar.gz: 7ad66b56b6e44eba2a90bbadac1029beb5dc2add24e8831d26a328c61ab49d71
5
5
  SHA512:
6
- metadata.gz: 1354650b100039d8692d117eaeaf79e3271e2ec178d6b0044372d7fed337ac614bec81296b31db6dea6549fc74ab151ac18fdfbf6af37fdd6f9cab0293169d15
7
- data.tar.gz: 48943f8b8ad265ea87beefc3764a36e7a4dead8868054c5664b337513e34579044ea12848e026352917812f4bf668e285c36e8f7a17335ffb54f70dce15e3f5e
6
+ metadata.gz: 3f9840c3921c7c89bce80f0a67a59f5639177ff8160f9a1563987b027d0e67d5ed783671e084ed2596199ada367839d0c10bc00d34901a56e4e0867048ee5bd6
7
+ data.tar.gz: 25ce6b02ba42827bd62f54da08eaa1f2302ee7461016c9d67dff8bbe32c1e8752cf6503ecc44161b071cd130087f56e932f0314f40ab76c849ed99695c095925
data/.circleci/config.yml CHANGED
@@ -1,8 +1,24 @@
1
1
  version: 2
2
+ workflows:
3
+ version: 2
4
+ test-and-build:
5
+ jobs:
6
+ - test:
7
+ filters:
8
+ tags:
9
+ only: /.*/
10
+ - build-and-release:
11
+ requires: [test]
12
+ filters:
13
+ tags:
14
+ only: /\d+\.\d+\.\d+/
15
+ branches:
16
+ only:
17
+ - master
2
18
  jobs:
3
- build:
19
+ test:
4
20
  docker:
5
- - image: darthjee/circleci_ruby_gems:0.2.3
21
+ - image: darthjee/circleci_ruby_gems:0.5.4
6
22
  environment:
7
23
  PROJECT: arstotzka
8
24
  steps:
@@ -34,3 +50,22 @@ jobs:
34
50
  - run:
35
51
  name: Check unit tests
36
52
  command: check_specs
53
+ build-and-release:
54
+ docker:
55
+ - image: darthjee/circleci_ruby_gems:0.5.4
56
+ environment:
57
+ PROJECT: arstotzka
58
+ steps:
59
+ - checkout
60
+ - run:
61
+ name: Bundle Install
62
+ command: bundle install
63
+ - run:
64
+ name: Signin
65
+ command: build_gem.sh signin
66
+ - run:
67
+ name: Build Gem
68
+ command: build_gem.sh build
69
+ - run:
70
+ name: Push Gem
71
+ command: build_gem.sh push
data/.rubocop.yml CHANGED
@@ -18,7 +18,7 @@ Style/ClassVars:
18
18
  Exclude:
19
19
  - spec/support/models/arstotzka/fetcher/class_variable.rb
20
20
 
21
- Layout/AlignHash:
21
+ Layout/HashAlignment:
22
22
  EnforcedColonStyle: table
23
23
 
24
24
  Metrics/BlockLength:
@@ -26,3 +26,12 @@ Metrics/BlockLength:
26
26
  - 'spec/**/*_spec.rb'
27
27
  - 'spec/support/**/*.rb'
28
28
  - '*.gemspec'
29
+
30
+ Style/HashEachMethods:
31
+ Enabled: true
32
+
33
+ Style/HashTransformKeys:
34
+ Enabled: true
35
+
36
+ Style/HashTransformValues:
37
+ Enabled: true
data/Dockerfile CHANGED
@@ -1,5 +1,5 @@
1
- FROM darthjee/ruby_gems:0.2.3 as base
2
- FROM darthjee/scripts:0.1.2 as scripts
1
+ FROM darthjee/ruby_gems:0.5.4 as base
2
+ FROM darthjee/scripts:0.1.8 as scripts
3
3
 
4
4
  ######################################
5
5
 
@@ -16,15 +16,9 @@ RUN bundle_builder.sh
16
16
  FROM base
17
17
  RUN mkdir lib/arstotzka -p
18
18
 
19
- USER root
20
-
21
- COPY --chown=app:app --from=builder /home/app/bundle/gems /usr/local/bundle/gems
22
- COPY --chown=app:app --from=builder /home/app/bundle/cache /usr/local/bundle/cache
23
- COPY --chown=app:app --from=builder /home/app/bundle/specifications /usr/local/bundle/specifications
24
- COPY --chown=app:app --from=builder /home/app/bundle/bin /usr/local/bundle/bin
25
- COPY --chown=app:app --from=builder /home/app/bundle/extensions /usr/local/bundle/extensions
19
+ COPY --chown=app:app --from=builder /home/app/bundle/ /usr/local/bundle/
26
20
 
27
21
  COPY --chown=app ./*.gemspec ./Gemfile /home/app/app/
28
22
  COPY --chown=app ./lib/arstotzka/version.rb /home/app/app/lib/arstotzka/
29
- USER app
23
+
30
24
  RUN bundle install
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  Arstotzka
2
2
  ========
3
+ [![Build Status](https://circleci.com/gh/darthjee/arstotzka.svg?style=shield)](https://circleci.com/gh/darthjee/arstotzka)
3
4
  [![Code Climate](https://codeclimate.com/github/darthjee/arstotzka/badges/gpa.svg)](https://codeclimate.com/github/darthjee/arstotzka)
4
5
  [![Test Coverage](https://codeclimate.com/github/darthjee/arstotzka/badges/coverage.svg)](https://codeclimate.com/github/darthjee/arstotzka/coverage)
5
6
  [![Issue Count](https://codeclimate.com/github/darthjee/arstotzka/badges/issue_count.svg)](https://codeclimate.com/github/darthjee/arstotzka)
6
7
  [![Gem Version](https://badge.fury.io/rb/arstotzka.svg)](https://badge.fury.io/rb/arstotzka)
8
+ [![Inline docs](http://inch-ci.org/github/darthjee/arstotzka.svg)](http://inch-ci.org/github/darthjee/arstotzka)
7
9
 
8
10
  ![arstotzka](https://raw.githubusercontent.com/darthjee/arstotzka/master/arstotzka.jpg)
9
11
 
@@ -19,7 +21,7 @@ JSON keys)
19
21
 
20
22
  Yard Documentation
21
23
  -------------------
22
- https://www.rubydoc.info/gems/arstotzka/1.4.3
24
+ [https://www.rubydoc.info/gems/arstotzka/1.6.2](https://www.rubydoc.info/gems/arstotzka/1.6.2)
23
25
 
24
26
  Instalation
25
27
  ---------------
@@ -112,6 +114,7 @@ Options
112
114
  - json: Method that contains the hash to be parsed (`:json` by default)
113
115
  - path: Path where to find the sub hash that contains the key (empty by default)
114
116
  - type: Type that the value must be cast into ([TypeCast](#typecast))
117
+ - before: method to be ran on result before any wrapping
115
118
 
116
119
  ## TypeCast
117
120
  The type casting, when the option `type` is passed, is done through the `Arstotzka::TypeCast` which can
data/arstotzka.gemspec CHANGED
@@ -19,24 +19,24 @@ 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.x'
23
- gem.add_runtime_dependency 'sinclair', '>= 1.4.1'
22
+ gem.add_runtime_dependency 'activesupport', '>= 5.2.4.2'
23
+ gem.add_runtime_dependency 'sinclair', '>= 1.6.5'
24
24
 
25
- gem.add_development_dependency 'bundler', '~> 1.16.1'
25
+ gem.add_development_dependency 'bundler', '1.16.1'
26
26
  gem.add_development_dependency 'pry', '0.12.2'
27
27
  gem.add_development_dependency 'pry-nav', '0.3.0'
28
- gem.add_development_dependency 'rake', '12.3.3'
29
- gem.add_development_dependency 'reek', '5.4.0'
30
- gem.add_development_dependency 'rspec', '3.8.0'
31
- gem.add_development_dependency 'rspec-core', '3.8.0'
32
- gem.add_development_dependency 'rspec-expectations', '3.8.3'
33
- gem.add_development_dependency 'rspec-mocks', '3.8.0'
34
- gem.add_development_dependency 'rspec-support', '3.8.0'
35
- gem.add_development_dependency 'rubocop', '0.73.0'
36
- gem.add_development_dependency 'rubocop-rspec', '1.33.0'
37
- gem.add_development_dependency 'rubycritic', '4.1.0'
38
- gem.add_development_dependency 'simplecov', '0.17.0'
39
- gem.add_development_dependency 'yard', '0.9.20'
28
+ gem.add_development_dependency 'rake', '13.0.1'
29
+ gem.add_development_dependency 'reek', '5.6.0'
30
+ gem.add_development_dependency 'rspec', '3.9.0'
31
+ gem.add_development_dependency 'rspec-core', '3.9.1'
32
+ gem.add_development_dependency 'rspec-expectations', '3.9.1'
33
+ gem.add_development_dependency 'rspec-mocks', '3.9.1'
34
+ gem.add_development_dependency 'rspec-support', '3.9.2'
35
+ gem.add_development_dependency 'rubocop', '0.80.1'
36
+ gem.add_development_dependency 'rubocop-rspec', '1.38.1'
37
+ gem.add_development_dependency 'rubycritic', '4.4.1'
38
+ gem.add_development_dependency 'simplecov', '0.17.1'
39
+ gem.add_development_dependency 'yard', '0.9.24'
40
40
  gem.add_development_dependency 'yardstick', '0.9.9'
41
41
 
42
42
  gem.add_development_dependency 'safe_attribute_assignment'
@@ -127,6 +127,14 @@ module Arstotzka
127
127
  # - +string+
128
128
  # - +float+
129
129
  #
130
+ # @return [Array<Sinclair::MethodDefinition>]
131
+ #
132
+ # @see Config
133
+ # @see MethodBuilder Arstotzka::MethodBuilder
134
+ # @see
135
+ # https://www.rubydoc.info/gems/activesupport/5.2.2/ActiveSupport/Concern
136
+ # ActiveSupport::Concern
137
+ #
130
138
  # @example
131
139
  # class MyModel
132
140
  # include Arstotzka
@@ -150,14 +158,6 @@ module Arstotzka
150
158
  # instance.first_name # returns 'John'
151
159
  # instance.age # returns 20
152
160
  # instance.cars # returns 2
153
- #
154
- # @return [Array<Sinclair::MethodDefinition>]
155
- #
156
- # @see Config
157
- # @see MethodBuilder Arstotzka::MethodBuilder
158
- # @see
159
- # https://www.rubydoc.info/gems/activesupport/5.2.2/ActiveSupport/Concern
160
- # ActiveSupport::Concern
161
161
  def expose(*attr_names, **options_hash)
162
162
  MethodBuilder.new(attr_names.map(&:to_sym), self, options_hash).build
163
163
  end
@@ -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(
@@ -20,20 +20,26 @@ module Arstotzka
20
20
 
21
21
  # Creates a new instance of Crawler
22
22
  #
23
- # @param block [Proc] block to be ran over the fetched value before returning it
24
- #
25
23
  # @overload initialize(options_hash={}, &block)
26
- # @param options [Hash] options of initialization
27
- # @option options keys [Array] keys of keys to be crawled
28
- # @option options case [Symbol] case type of the keys
24
+ # @param options_hash [Hash] options of initialization
25
+ # @option options_hash keys [Array] keys of keys to be crawled
26
+ # @option options_hash case [Symbol] case type of the keys
29
27
  # - snake: snake_cased keys
30
28
  # - lower_camel: lowerCamelCased keys
31
29
  # - upper_camel: UperCamelCased keys
32
- # @option options compact [Boolean] flag signallying if nil values should be removed of array
33
- # @option options default [Object] default value to be returned when failing to fetch a value
30
+ # @option options_hash compact [TrueClass,FalseClass] flag signallying if
31
+ # nil values should be removed of array
32
+ # @option options_hash default [Object] default value to be returned when
33
+ # failing to fetch a value
34
+ # @param block [Proc] block to be ran over the
35
+ # fetched value before returning it
34
36
  #
35
37
  # @overload initialize(options, &block)
36
38
  # @param options [Arstotzka::Options] options of initialization object
39
+ # @param block [Proc] block to be ran over the
40
+ # fetched value before returning it
41
+ #
42
+ # @example (see Arstotzka::Crawler)
37
43
  def initialize(options = {}, &block)
38
44
  self.options = options
39
45
  @block = block
@@ -92,9 +98,42 @@ module Arstotzka
92
98
 
93
99
  private
94
100
 
95
- # @private
96
101
  attr_reader :block, :options
102
+ # @method block
103
+ # @api private
104
+ # @private
105
+ #
106
+ # Proc to be ran over the fetched value before returning it
107
+ #
108
+ # @return [Proc]
109
+
110
+ # @method options
111
+ # @api private
112
+ # @private
113
+ #
114
+ # Options of initialization object
115
+ #
116
+ # @return [Arstotzka::Options]
117
+
97
118
  delegate :compact, :default, to: :options
119
+ # @method compact
120
+ # @api private
121
+ # @private
122
+ #
123
+ # Flag for compacting the resulting array
124
+ #
125
+ # When this flag is true, all nil elements are removed
126
+ # from the resulting array
127
+ #
128
+ # @return [TrueClass,FalseClass]
129
+
130
+ # @method default
131
+ # @api private
132
+ # @private
133
+ #
134
+ # Default value to be returned when failing to fetch a value
135
+ #
136
+ # @return [Object]
98
137
 
99
138
  # Fetch the value from hash by crawling the keys
100
139
  #
@@ -13,15 +13,16 @@ module Arstotzka
13
13
  class Cache
14
14
  include Base
15
15
 
16
- # @param block [Proc] block to be executed in case
17
- # variable is not cached
18
- #
19
16
  # @overload initialize(options, &block)
20
17
  # @param options [Arstotzka::Options] options passed
21
- # as options object
18
+ # as options object
19
+ # @param block [Proc] block to be executed in case
20
+ # variable is not cached
22
21
  #
23
22
  # @overload initialize(options_hash, &block)
24
23
  # @param options_hash [Hash] opttions passed as hash
24
+ # @param block [Proc] block to be executed in case
25
+ # variable is not cached
25
26
  def initialize(options_hash = {}, &block)
26
27
  self.options = options_hash
27
28
  @block = block
@@ -243,7 +243,9 @@ module Arstotzka
243
243
  # # Danny LJ Robert Richard
244
244
  # # Linda Ariel
245
245
  # # ]
246
- class Options < ::OpenStruct
246
+ class Options < Sinclair::Options
247
+ with_options Config::DEFAULT_CONFIGS
248
+ with_options :full_path, :key, :instance, :path
247
249
  # Creates a new instance of Options
248
250
  #
249
251
  # @param options_hash [Hash] options hash
@@ -281,7 +283,7 @@ module Arstotzka
281
283
  #
282
284
  # @return [Array<String>]
283
285
  def keys
284
- return full_path.split('.') if full_path
286
+ return full_path.to_s.split('.') if full_path
285
287
  return [key.to_s] unless path&.present?
286
288
 
287
289
  [path, key].compact.join('.').split('.')
@@ -71,6 +71,9 @@ module Arstotzka
71
71
 
72
72
  # Converts a value to integer
73
73
  #
74
+ # @param value [Object] object to be converted
75
+ # to integer
76
+ #
74
77
  # @return [Integer]
75
78
  #
76
79
  # @example Casting to Integer
@@ -95,6 +98,9 @@ module Arstotzka
95
98
 
96
99
  # Converts value to string
97
100
  #
101
+ # @param value [Object] object to be converted
102
+ # to string
103
+ #
98
104
  # @return [String]
99
105
  #
100
106
  # @example Casting to String
@@ -121,6 +127,9 @@ module Arstotzka
121
127
 
122
128
  # Converts value to float
123
129
  #
130
+ # @param value [Object] object to be converted
131
+ # to float
132
+ #
124
133
  # @return [Float]
125
134
  #
126
135
  # @example Casting to Float
@@ -145,6 +154,9 @@ module Arstotzka
145
154
 
146
155
  # Converts value to Symbol
147
156
  #
157
+ # @param value [Object] object to be converted
158
+ # to symbol
159
+ #
148
160
  # @return [Symbol]
149
161
  #
150
162
  # @example Casting to Symbol
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Arstotzka
4
- VERSION = '1.4.3'
4
+ VERSION = '1.6.2'
5
5
  end
@@ -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
@@ -55,7 +55,12 @@ describe Arstotzka::Config do
55
55
  flatten: false,
56
56
  json: :json,
57
57
  klass: Person,
58
- type: :none
58
+ type: :none,
59
+ full_path: nil,
60
+ key: nil,
61
+ instance: nil,
62
+ path: nil,
63
+ before: nil
59
64
  }
60
65
  end
61
66
 
@@ -49,6 +49,7 @@ describe Arstotzka::Options do
49
49
  ]
50
50
  end
51
51
 
52
+ # rubocop:disable RSpec/LeakyConstantDeclaration
52
53
  before do
53
54
  module Arstotzka::TypeCast
54
55
  def to_symbolized_hash(value)
@@ -56,12 +57,14 @@ describe Arstotzka::Options do
56
57
  end
57
58
  end
58
59
  end
60
+ # rubocop:enable RSpec/LeakyConstantDeclaration
59
61
 
60
62
  it 'returns inflated drinks' do
61
63
  expect(instance.drinks).to eq(expected)
62
64
  end
63
65
  end
64
66
 
67
+ # rubocop:disable RSpec/SubjectStub
65
68
  describe 'Using cached, compact, after and full_path' do
66
69
  let(:clazz) { Application }
67
70
 
@@ -85,9 +88,7 @@ describe Arstotzka::Options do
85
88
  end
86
89
 
87
90
  before do
88
- # rubocop:disable RSpec/SubjectStub
89
91
  allow(instance).to receive(:warn)
90
- # rubocop:enable RSpec/SubjectStub
91
92
  end
92
93
 
93
94
  it 'Returns created users' do
@@ -100,6 +101,7 @@ describe Arstotzka::Options do
100
101
  expect(instance).to have_received(:warn).exactly(3).times
101
102
  end
102
103
  end
104
+ # rubocop:enable RSpec/SubjectStub
103
105
 
104
106
  describe 'working with snake case hash' do
105
107
  let(:clazz) { JobSeeker }
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: truie
1
+ # frozen_string_literal: true
2
2
 
3
3
  describe Arstotzka::Wrapper do
4
4
  subject(:wrapper) { described_class.new(klass: klass, type: type) }
@@ -10,13 +10,22 @@ describe Arstotzka::Config do
10
10
  end
11
11
 
12
12
  describe '#options' do
13
+ let(:expected_options_hash) do
14
+ described_class::DEFAULT_CONFIGS.merge(
15
+ full_path: nil,
16
+ key: nil,
17
+ instance: nil,
18
+ path: nil
19
+ )
20
+ end
21
+
13
22
  it do
14
23
  expect(config.options).to be_a(Arstotzka::Options)
15
24
  end
16
25
 
17
26
  it 'generates options with default values' do
18
27
  expect(config.options.to_h)
19
- .to eq(described_class::DEFAULT_CONFIGS)
28
+ .to eq(expected_options_hash)
20
29
  end
21
30
 
22
31
  context 'when configuring it' do
@@ -31,7 +40,12 @@ describe Arstotzka::Config do
31
40
  flatten: true,
32
41
  json: :@hash,
33
42
  klass: Account,
34
- type: :string
43
+ type: :string,
44
+ full_path: nil,
45
+ key: nil,
46
+ instance: nil,
47
+ path: nil,
48
+ before: :before_action
35
49
  }
36
50
  end
37
51
 
@@ -47,6 +61,7 @@ describe Arstotzka::Config do
47
61
  json :@hash
48
62
  klass Account
49
63
  type :string
64
+ before :before_action
50
65
  end
51
66
  end
52
67
 
@@ -72,7 +87,12 @@ describe Arstotzka::Config do
72
87
  flatten: true,
73
88
  json: :@hash,
74
89
  klass: Account,
75
- type: :string
90
+ type: :string,
91
+ full_path: nil,
92
+ key: nil,
93
+ instance: nil,
94
+ path: nil,
95
+ before: nil
76
96
  }
77
97
  end
78
98
 
@@ -163,7 +163,7 @@ describe Arstotzka::Fetcher do
163
163
  end
164
164
  end
165
165
 
166
- context 'when json is an instance variable' do
166
+ context 'when json is an class variable' do
167
167
  let(:instance) { described_class::ClassVariable.new }
168
168
  let(:hash) { { name: 'John Doe' } }
169
169
  let(:options_hash) { { key: :name, json: :@@json } }
@@ -159,13 +159,13 @@ describe Arstotzka::Options do
159
159
  end
160
160
  end
161
161
 
162
+ # rubocop:disable RSpec/SubjectStub
163
+ # rubocop:disable RSpec/AnyInstance
162
164
  describe '#klass' do
163
- # rubocop:disable RSpec/AnyInstance
164
165
  before do
165
166
  allow_any_instance_of(described_class)
166
167
  .to receive(:warn)
167
168
  end
168
- # rubocop:enable RSpec/AnyInstance
169
169
 
170
170
  context 'when initializing with old class key' do
171
171
  let(:options_hash) { { class: Star } }
@@ -191,6 +191,8 @@ describe Arstotzka::Options do
191
191
  end
192
192
  end
193
193
  end
194
+ # rubocop:enable RSpec/AnyInstance
195
+ # rubocop:enable RSpec/SubjectStub
194
196
 
195
197
  describe '#merge' do
196
198
  let(:options_hash) { { json: :hash, default: 10 } }
@@ -289,5 +291,31 @@ describe Arstotzka::Options do
289
291
  end
290
292
  end
291
293
  end
294
+
295
+ context 'when full_path is a symbol' do
296
+ let(:full_path) { :account }
297
+
298
+ context 'when path is nil' do
299
+ it 'returns splitted full path' do
300
+ expect(options.keys).to eq(%w[account])
301
+ end
302
+ end
303
+
304
+ context 'when path is empty' do
305
+ let(:path) { '' }
306
+
307
+ it 'returns splitted full path' do
308
+ expect(options.keys).to eq(%w[account])
309
+ end
310
+ end
311
+
312
+ context 'when path is not empty' do
313
+ let(:path) { 'account.person' }
314
+
315
+ it 'returns splitted full path' do
316
+ expect(options.keys).to eq(%w[account])
317
+ end
318
+ end
319
+ end
292
320
  end
293
321
  end
@@ -8,7 +8,7 @@ describe Arstotzka::Wrapper do
8
8
  let(:hash) { { a: 1 } }
9
9
 
10
10
  describe '#wrap' do
11
- let(:value) { hash }
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 otpion' do
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' }
@@ -10,6 +10,10 @@ module Arstotzka
10
10
  private
11
11
 
12
12
  attr_reader :json
13
+
14
+ def ensure_age(hash)
15
+ hash.merge(age: 10)
16
+ end
13
17
  end
14
18
  end
15
19
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Person
4
- attr_reader :name
4
+ attr_reader :name, :age
5
5
 
6
6
  def initialize(name)
7
7
  @name = name
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arstotzka
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.6.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-11-13 00:00:00.000000000 Z
11
+ date: 2021-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.x
19
+ version: 5.2.4.2
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.x
26
+ version: 5.2.4.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sinclair
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.4.1
33
+ version: 1.6.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.4.1
40
+ version: 1.6.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
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
54
  version: 1.16.1
55
55
  - !ruby/object:Gem::Dependency
@@ -86,168 +86,168 @@ dependencies:
86
86
  requirements:
87
87
  - - '='
88
88
  - !ruby/object:Gem::Version
89
- version: 12.3.3
89
+ version: 13.0.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - '='
95
95
  - !ruby/object:Gem::Version
96
- version: 12.3.3
96
+ version: 13.0.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: reek
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 5.4.0
103
+ version: 5.6.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 5.4.0
110
+ version: 5.6.0
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: rspec
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 3.8.0
117
+ version: 3.9.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 3.8.0
124
+ version: 3.9.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: rspec-core
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - '='
130
130
  - !ruby/object:Gem::Version
131
- version: 3.8.0
131
+ version: 3.9.1
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
- version: 3.8.0
138
+ version: 3.9.1
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rspec-expectations
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
143
  - - '='
144
144
  - !ruby/object:Gem::Version
145
- version: 3.8.3
145
+ version: 3.9.1
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - '='
151
151
  - !ruby/object:Gem::Version
152
- version: 3.8.3
152
+ version: 3.9.1
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: rspec-mocks
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - '='
158
158
  - !ruby/object:Gem::Version
159
- version: 3.8.0
159
+ version: 3.9.1
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - '='
165
165
  - !ruby/object:Gem::Version
166
- version: 3.8.0
166
+ version: 3.9.1
167
167
  - !ruby/object:Gem::Dependency
168
168
  name: rspec-support
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 3.8.0
173
+ version: 3.9.2
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 3.8.0
180
+ version: 3.9.2
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: rubocop
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
- version: 0.73.0
187
+ version: 0.80.1
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - '='
193
193
  - !ruby/object:Gem::Version
194
- version: 0.73.0
194
+ version: 0.80.1
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: rubocop-rspec
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - '='
200
200
  - !ruby/object:Gem::Version
201
- version: 1.33.0
201
+ version: 1.38.1
202
202
  type: :development
203
203
  prerelease: false
204
204
  version_requirements: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - '='
207
207
  - !ruby/object:Gem::Version
208
- version: 1.33.0
208
+ version: 1.38.1
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: rubycritic
211
211
  requirement: !ruby/object:Gem::Requirement
212
212
  requirements:
213
213
  - - '='
214
214
  - !ruby/object:Gem::Version
215
- version: 4.1.0
215
+ version: 4.4.1
216
216
  type: :development
217
217
  prerelease: false
218
218
  version_requirements: !ruby/object:Gem::Requirement
219
219
  requirements:
220
220
  - - '='
221
221
  - !ruby/object:Gem::Version
222
- version: 4.1.0
222
+ version: 4.4.1
223
223
  - !ruby/object:Gem::Dependency
224
224
  name: simplecov
225
225
  requirement: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - '='
228
228
  - !ruby/object:Gem::Version
229
- version: 0.17.0
229
+ version: 0.17.1
230
230
  type: :development
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - '='
235
235
  - !ruby/object:Gem::Version
236
- version: 0.17.0
236
+ version: 0.17.1
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: yard
239
239
  requirement: !ruby/object:Gem::Requirement
240
240
  requirements:
241
241
  - - '='
242
242
  - !ruby/object:Gem::Version
243
- version: 0.9.20
243
+ version: 0.9.24
244
244
  type: :development
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
248
  - - '='
249
249
  - !ruby/object:Gem::Version
250
- version: 0.9.20
250
+ version: 0.9.24
251
251
  - !ruby/object:Gem::Dependency
252
252
  name: yardstick
253
253
  requirement: !ruby/object:Gem::Requirement