deep_fetch 0.0.2 → 0.0.3

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.
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *.gem
2
+ coverage/*
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # DeepFetch
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/pewniak747/deep_fetch.png?branch=master)](http://travis-ci.org/pewniak747/deep_fetch)
4
+ [![Coverage Status](https://coveralls.io/repos/pewniak747/deep_fetch/badge.png?branch=master)](https://coveralls.io/r/pewniak747/deep_fetch)
5
+ [![Dependency Status](https://gemnasium.com/pewniak747/deep_fetch.png)](https://gemnasium.com/pewniak747/deep_fetch)
6
+ [![Gem Version](https://badge.fury.io/rb/deep_fetch.png)](http://badge.fury.io/rb/deep_fetch)
4
7
 
5
8
  Easily fetch values from nested ruby hashes.
6
9
 
data/deep_fetch.gemspec CHANGED
@@ -16,4 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "coveralls"
19
21
  end
@@ -8,7 +8,10 @@ class Hash
8
8
  elsif value.kind_of?(Array) && args.size > 0
9
9
  value = value[args.shift]
10
10
  value.deep_fetch(*args, &block)
11
- else value
11
+ elsif args.size > 0
12
+ {}.fetch(args.shift, &block)
13
+ else
14
+ value
12
15
  end
13
16
  end
14
17
  end
@@ -1,3 +1,3 @@
1
1
  module DeepFetch
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,62 +2,77 @@ require 'minitest/spec'
2
2
  require 'minitest/autorun'
3
3
 
4
4
  require_relative '../lib/deep_fetch'
5
+ require 'coveralls'
6
+
7
+ Coveralls.wear!
5
8
 
6
9
  describe Hash do
7
10
  describe "deep_fetch" do
8
- it "must_equal return value from hash" do
9
- {:foo => :bar}.deep_fetch(:foo).must_equal :bar
10
- end
11
+ describe "must return value" do
12
+ it "from shallow hash" do
13
+ {:foo => :bar}.deep_fetch(:foo).must_equal :bar
14
+ end
11
15
 
12
- it "must_equal return value from block if key not found" do
13
- {:foo => :bar}.deep_fetch(:baz) { :boo } .must_equal :boo
14
- end
16
+ it "from block if key was not found" do
17
+ {:foo => :bar}.deep_fetch(:baz) { :boo } .must_equal :boo
18
+ end
15
19
 
16
- it "must_equal rise KeyError if no block and key not found" do
17
- lambda do
18
- {:foo => :bar}.deep_fetch(:baz).must_equal
19
- end.must_raise(KeyError)
20
- end
20
+ it "from deep hash" do
21
+ {:foo => {:bar => :baz}}.deep_fetch(:foo, :bar).must_equal :baz
22
+ end
21
23
 
22
- it "must_equal fetch from deep hash" do
23
- {:foo => {:bar => :baz}}.deep_fetch(:foo, :bar).must_equal :baz
24
- end
24
+ it "from block if key not found in deep hash" do
25
+ {:foo => {:bar => :baz}}.deep_fetch(:foo, :baz) { :boo } .must_equal :boo
26
+ end
25
27
 
26
- it "must_equal return value from block if key not found in deep hash" do
27
- {:foo => {:bar => :baz}}.deep_fetch(:foo, :baz) { :boo } .must_equal :boo
28
- end
28
+ it "from arrays in deep hash" do
29
+ {:foo => [nil, {:bar => :baz}]}.deep_fetch(:foo, 1, :bar).must_equal :baz
30
+ end
29
31
 
30
- it "must_equal raise KeyError if key not found in deep hash and no block" do
31
- lambda do
32
- {:foo => {:bar => :baz}}.deep_fetch(:foo, :baz)
33
- end.must_raise(KeyError)
34
- end
32
+ it "of hash from deep hash" do
33
+ {:foo => {:bar => :baz}}.deep_fetch(:foo).must_equal({:bar => :baz})
34
+ end
35
35
 
36
- it "must_equal return values from arrays in deep hash" do
37
- {:foo => [nil, {:bar => :baz}]}.deep_fetch(:foo, 1, :bar).must_equal :baz
38
- end
36
+ it "of array from deep hash" do
37
+ {:foo => {:bar => [:baz]}}.deep_fetch(:foo, :bar).must_equal [:baz]
38
+ end
39
39
 
40
- it "must_equal fetch hash from deep hash" do
41
- {:foo => {:bar => :baz}}.deep_fetch(:foo).must_equal({:bar => :baz})
40
+ it "of hash from deeper hash" do
41
+ {:foo => {:bar => {:baz => :boo}}}.deep_fetch(:foo, :bar).must_equal({:baz => :boo})
42
+ end
42
43
  end
43
44
 
44
- it "must_equal fetch array from deep hash" do
45
- {:foo => {:bar => [:baz]}}.deep_fetch(:foo, :bar).must_equal [:baz]
45
+ describe "must rise KeyError" do
46
+ it "if key not found in hash and no block provided" do
47
+ lambda do
48
+ {:foo => :bar}.deep_fetch(:baz).must_equal
49
+ end.must_raise(KeyError)
50
+ end
51
+
52
+ it "if key not found in deep hash and no block provided" do
53
+ lambda do
54
+ {:foo => {:bar => :baz}}.deep_fetch(:foo, :baz)
55
+ end.must_raise(KeyError)
56
+ end
57
+
58
+ it "must raise KeyError when deep key does not exist" do
59
+ lambda do
60
+ {:foo => :bar}.deep_fetch(:foo, :foo)
61
+ end.must_raise(KeyError)
62
+ end
46
63
  end
47
64
 
48
- it "must_equal fetch hash from deeper hash" do
49
- {:foo => {:bar => {:baz => :boo}}}.deep_fetch(:foo, :bar).must_equal({:baz => :boo})
65
+ describe "must rise ArgumentError" do
66
+ it "if invoked without arguments" do
67
+ lambda do
68
+ {}.deep_fetch
69
+ end.must_raise(ArgumentError)
70
+ end
50
71
  end
51
72
 
52
- it "must_equal not evaluate a default block when fetching from deep hash" do
73
+ it "must not evaluate a default block when fetching from deep hash" do
53
74
  bomb = ->() { raise "BOOM" }
54
75
  {:foo => {:bar => :baz}}.deep_fetch(:foo, :bar, &bomb).must_equal :baz
55
76
  end
56
-
57
- it "must raise ArgumentError if invoked without arguments" do
58
- lambda do
59
- {}.deep_fetch
60
- end.must_raise(ArgumentError)
61
- end
62
77
  end
63
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_fetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-24 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2013-04-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: coveralls
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  description: easily fetch values from nested ruby hashes
15
31
  email:
16
32
  - pewniak747@gmail.com
@@ -48,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
64
  version: '0'
49
65
  requirements: []
50
66
  rubyforge_project:
51
- rubygems_version: 1.8.24
67
+ rubygems_version: 1.8.23
52
68
  signing_key:
53
69
  specification_version: 3
54
70
  summary: easily fetch values from nested ruby hashes