deep_fetch 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # DeepFetch
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/pewniak747/deep_fetch.png?branch=master)](http://travis-ci.org/pewniak747/deep_fetch)
4
+
3
5
  Easily fetch values from nested ruby hashes.
4
6
 
5
7
  ## Installation
data/Rakefile CHANGED
@@ -1 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.pattern = "spec/*_spec.rb"
6
+ end
7
+
8
+ task :default => :test
@@ -1,9 +1,9 @@
1
1
  class Hash
2
2
  def deep_fetch *args, &block
3
- return self if args.size == 0
3
+ raise ArgumentError.new("wrong number of arguments (0 for 1..n)") if args.empty?
4
4
 
5
5
  value = fetch(args.shift, &block)
6
- if value.kind_of?(Hash)
6
+ if value.kind_of?(Hash) && args.size > 0
7
7
  value.deep_fetch(*args, &block)
8
8
  elsif value.kind_of?(Array) && args.size > 0
9
9
  value = value[args.shift]
@@ -1,3 +1,3 @@
1
1
  module DeepFetch
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -45,9 +45,19 @@ describe Hash do
45
45
  {:foo => {:bar => [:baz]}}.deep_fetch(:foo, :bar).must_equal [:baz]
46
46
  end
47
47
 
48
+ it "must_equal fetch hash from deeper hash" do
49
+ {:foo => {:bar => {:baz => :boo}}}.deep_fetch(:foo, :bar).must_equal({:baz => :boo})
50
+ end
51
+
48
52
  it "must_equal not evaluate a default block when fetching from deep hash" do
49
53
  bomb = ->() { raise "BOOM" }
50
54
  {:foo => {:bar => :baz}}.deep_fetch(:foo, :bar, &bomb).must_equal :baz
51
55
  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
52
62
  end
53
63
  end
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ notifications:
7
+ email:
8
+ recipients:
9
+ - pewniak747@gmail.com
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-15 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: easily fetch values from nested ruby hashes
15
15
  email:
@@ -27,6 +27,7 @@ files:
27
27
  - lib/deep_fetch/core_ext.rb
28
28
  - lib/deep_fetch/version.rb
29
29
  - spec/deep_fetch_spec.rb
30
+ - travis.yml
30
31
  homepage: https://github.com/pewniak747/deep_fetch
31
32
  licenses: []
32
33
  post_install_message:
@@ -47,7 +48,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
48
  version: '0'
48
49
  requirements: []
49
50
  rubyforge_project:
50
- rubygems_version: 1.8.23
51
+ rubygems_version: 1.8.24
51
52
  signing_key:
52
53
  specification_version: 3
53
54
  summary: easily fetch values from nested ruby hashes