kernel-fetch_in 0.1.0 → 0.2.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- N2ZiMjU0NWM0Y2Q4ZmNkY2IyNDMwMmM5ODIyZTY3YzVlNWQ1ODgxMw==
4
+ OWRiYTIwMjVkMDc1Y2E3MGQxYzczMjg2MGVjMTc0MTI2NjBlYjUyZQ==
5
5
  data.tar.gz: !binary |-
6
- OThkNGE0NjEzZjc0ODE5MTVkNzUxMWY3OGJlZDllMjEzYTlkYTNmNQ==
6
+ NWMxNzUzNWI1YTI1YzkyOGE0M2FiOGQxNDU0MzNkYjYwMmYyZDVhZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWIzMzYyZjRmZjVlZmUxMjY5ZjUyOWI1Y2FhNTMxM2NlYjQwNTJmYWM2NTVk
10
- YWZhZWU0ZWY4Yzc3ZmFjNGFhNjNkMDA5MWU0YmI3MTBmZGYzYTUzMjZkMWM5
11
- NmFmNWY5NzU4MjA2MTQ0NzE5MjUzN2U2MzAxYjUwNWY3MDAyZGU=
9
+ YTNjMGEwNzBlYmViMDE5NmVkZGQ2OGI1MzY1OTIwYjZjNWMyYzcxMzExOTJi
10
+ ODdkZTg4NjFlZDljYjQ0NTNjMDcyYjlkNzUxMGQzYjlhMGJhNjVlZmJjM2Iz
11
+ MDhiODQ3NzU5NGM2Mjk4YjE1NmY2YjI4MWZkN2MxZTVjMDcyZWI=
12
12
  data.tar.gz: !binary |-
13
- NDFkOTVlOWU2NjZhM2FmM2MzNGRhZWY4MjE0Y2QxMWNhZmZlODc5NjU1MTFk
14
- YWQxZDcwYWNkZTc5YTY4ODQ2MjM1MDlmOWVlZGYzOWNiNzkxZGRjMTg1MDFj
15
- ZDM1MDM2Y2I4NzQyNDI2YTMwYTRjOGVmZGRiMjJmOTlmMjJhYzg=
13
+ YmZiZjRiMmI0YzM4ZWM2NDAwOWE4ODUwMzFmZWEzYjE3ZGI4Yzk3ZWM3MGI5
14
+ NjgwOTdjYmE0MmEyODU0MjBhMDA2YzRmMmFhMmQ4MGZiOTM4ZDE3ZDgxNzgx
15
+ ZjFlNTAyN2EwODFmNGE5ZjMxMmM2YjIxMzc2MWRhNzIyMDU1OTA=
@@ -0,0 +1,13 @@
1
+ module FetchIn
2
+ def self.fetch_in(collection, first_key, *rest)
3
+ keys = [first_key] + rest
4
+ last_key = nil
5
+ keys.reduce(collection) do |c, k|
6
+ last_key = k
7
+ c.fetch(k)
8
+ end
9
+ rescue IndexError
10
+ raise unless block_given?
11
+ yield last_key
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module FetchIn
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,15 +1,7 @@
1
- require 'kernel/fetch_in'
1
+ require 'fetch_in'
2
2
 
3
3
  module Kernel
4
- def fetch_in(collection, *keys)
5
- last_key = nil
6
- keys.reduce(collection) do |c, k|
7
- last_key = k
8
- c.fetch(k)
9
- end
10
- rescue IndexError, KeyError
11
- raise unless block_given?
12
- yield last_key
13
- end
4
+ extend Forwardable
5
+ def_delegator :FetchIn, :fetch_in
14
6
  private :fetch_in
15
7
  end
@@ -6,6 +6,12 @@ RSpec.describe Kernel do
6
6
  let(:value) { double }
7
7
 
8
8
  describe '#fetch_in' do
9
+ context 'passed no key arguments' do
10
+ it 'raises an ArgumentError' do
11
+ expect { fetch_in(collection) }.to raise_error ArgumentError
12
+ end
13
+ end
14
+
9
15
  context 'passed a single key argument' do
10
16
  it 'returns what #fetch on the collection argument returns' do
11
17
  allow(collection).to receive(:fetch).with(key) { value }
@@ -13,8 +19,8 @@ RSpec.describe Kernel do
13
19
  end
14
20
 
15
21
  [IndexError, KeyError].each do |err|
16
- context "when #fetch raises a #{err}" do
17
- before { allow(collection).to receive(:fetch).with(key) { raise err } }
22
+ context "when #fetch raises #{err}" do
23
+ before { allow(collection).to receive(:fetch).with(key) { fail err } }
18
24
 
19
25
  it 'raises that Error' do
20
26
  expect { fetch_in(collection, key) }.to raise_error err
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kernel-fetch_in
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Novitski
@@ -53,6 +53,7 @@ files:
53
53
  - README.md
54
54
  - Rakefile
55
55
  - kernel-fetch_in.gemspec
56
+ - lib/fetch_in.rb
56
57
  - lib/fetch_in/version.rb
57
58
  - lib/kernel/fetch_in.rb
58
59
  - spec/kernel/fetch_in_spec.rb