verbose_hash_fetch 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/verbose_hash_fetch.rb +5 -5
- data/spec/verbose_hash_fetch_spec.rb +6 -6
- data/verbose_hash_fetch.gemspec +1 -1
- metadata +14 -19
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 04e19dbd715b6342c3c5c5094cf79555c3974809
|
4
|
+
data.tar.gz: 8b88b59efbb6efa6f5b46144d481c7b44e2fd297
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45841f7bb05767492b593546d89fb001b3d067ee7866675036d75edb847a35d3756a74b11e1e89080c111efade97de9185145c83e30641e584a682f0dd823bda
|
7
|
+
data.tar.gz: 59fb637d7a006596d1057720c43be00a11cfcaf8858e263ade6a6526fd8899c975446cfa6030257f073be3dbff4c4e6fa790403cd69d12a8e9d8a3d99a9f3c28
|
data/lib/verbose_hash_fetch.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class KeyError
|
2
|
-
attr_accessor :
|
2
|
+
attr_accessor :_original_hash
|
3
3
|
|
4
4
|
def to_s
|
5
|
-
if
|
6
|
-
"#{super} in #{
|
5
|
+
if _original_hash
|
6
|
+
"#{super} in #{_original_hash.class}: #{_original_hash.inspect}"
|
7
7
|
else
|
8
8
|
super
|
9
9
|
end
|
@@ -15,9 +15,9 @@ class Hash
|
|
15
15
|
alias_method :_fetch, :fetch
|
16
16
|
|
17
17
|
def fetch(*args, &block)
|
18
|
-
_fetch
|
18
|
+
_fetch(*args, &block)
|
19
19
|
rescue KeyError => key_error
|
20
|
-
key_error.
|
20
|
+
key_error._original_hash = self
|
21
21
|
raise
|
22
22
|
end
|
23
23
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'verbose_hash_fetch'
|
2
2
|
|
3
|
-
describe "VerboseHashFetch" do
|
3
|
+
RSpec.describe "VerboseHashFetch" do
|
4
4
|
|
5
5
|
let(:hash) { { :foo => "bar" } }
|
6
6
|
|
7
7
|
context "with one argument" do
|
8
8
|
|
9
9
|
it "fetches an existing key" do
|
10
|
-
hash.fetch(:foo).
|
10
|
+
expect(hash.fetch(:foo)).to eq "bar"
|
11
11
|
end
|
12
12
|
|
13
13
|
it "raises a KeyError for non existing keys" do
|
@@ -23,11 +23,11 @@ describe "VerboseHashFetch" do
|
|
23
23
|
context "with two arguments" do
|
24
24
|
|
25
25
|
it "fetches the existing value" do
|
26
|
-
hash.fetch(:foo, "default").
|
26
|
+
expect(hash.fetch(:foo, "default")).to eq "bar"
|
27
27
|
end
|
28
28
|
|
29
29
|
it "uses the 2nd argument when key not found" do
|
30
|
-
hash.fetch(:bar, "default").
|
30
|
+
expect(hash.fetch(:bar, "default")).to eq "default"
|
31
31
|
end
|
32
32
|
|
33
33
|
end
|
@@ -35,11 +35,11 @@ describe "VerboseHashFetch" do
|
|
35
35
|
context "with a block" do
|
36
36
|
|
37
37
|
it "fetches the existing value" do
|
38
|
-
hash.fetch(:foo) { "default" }.
|
38
|
+
expect(hash.fetch(:foo) { "default" }).to eq "bar"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "evaluates the block when key not found" do
|
42
|
-
hash.fetch(:bar) { |k| "default #{k}" }.
|
42
|
+
expect(hash.fetch(:bar) { |k| "default #{k}" }).to eq "default bar"
|
43
43
|
end
|
44
44
|
|
45
45
|
end
|
data/verbose_hash_fetch.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "verbose_hash_fetch"
|
7
|
-
gem.version = '0.0.
|
7
|
+
gem.version = '0.0.2'
|
8
8
|
gem.authors = ["iain"]
|
9
9
|
gem.email = ["iain@iain.nl"]
|
10
10
|
gem.description = %q{Monkey patches Hash#fetch to also show the entire hash in the error}
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: verbose_hash_fetch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- iain
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-10-08 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
description: Monkey patches Hash#fetch to also show the entire hash in the error
|
@@ -50,8 +45,8 @@ executables: []
|
|
50
45
|
extensions: []
|
51
46
|
extra_rdoc_files: []
|
52
47
|
files:
|
53
|
-
- .gitignore
|
54
|
-
- .rspec
|
48
|
+
- ".gitignore"
|
49
|
+
- ".rspec"
|
55
50
|
- Gemfile
|
56
51
|
- LICENSE.txt
|
57
52
|
- README.md
|
@@ -61,27 +56,27 @@ files:
|
|
61
56
|
- verbose_hash_fetch.gemspec
|
62
57
|
homepage: https://github.com/iain/verbose_hash_fetch
|
63
58
|
licenses: []
|
59
|
+
metadata: {}
|
64
60
|
post_install_message:
|
65
61
|
rdoc_options: []
|
66
62
|
require_paths:
|
67
63
|
- lib
|
68
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
65
|
requirements:
|
71
|
-
- -
|
66
|
+
- - ">="
|
72
67
|
- !ruby/object:Gem::Version
|
73
68
|
version: '0'
|
74
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
70
|
requirements:
|
77
|
-
- -
|
71
|
+
- - ">="
|
78
72
|
- !ruby/object:Gem::Version
|
79
73
|
version: '0'
|
80
74
|
requirements: []
|
81
75
|
rubyforge_project:
|
82
|
-
rubygems_version:
|
76
|
+
rubygems_version: 2.2.2
|
83
77
|
signing_key:
|
84
|
-
specification_version:
|
78
|
+
specification_version: 4
|
85
79
|
summary: Monkey patches Hash#fetch to also show the entire hash in the error
|
86
80
|
test_files:
|
87
81
|
- spec/verbose_hash_fetch_spec.rb
|
82
|
+
has_rdoc:
|