seekable_hash 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c51f34a41af32f231ce041e5b762c2928caf3c7
4
+ data.tar.gz: 06f89b7099d5288f45499f36a857795a458a5b0a
5
+ SHA512:
6
+ metadata.gz: 6b120408784bf343906a0aba2fc18017d091aa921e6e483bb85559213397325fb0a1df9d804c6fae96fedf9c98e51bd7c554e2e6db651341c9d8b4a4ec73eca6
7
+ data.tar.gz: e6a06afbdc9294f82799f86a345d48854210bf88e875b3a9bf26f4137ae4a559cbf0d7a1de07b843c520f5a3bf052945d3efe2225d953fe3ceef9aee8e97074b
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
4
+ - jruby-18mode
5
+ - jruby-19mode
6
+ - rbx-2
7
+ - ruby-head
8
+ - jruby-head
9
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seekable_hash.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Derrick Reimer
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # SeekableHash
2
+
3
+ [![Code Climate](https://codeclimate.com/github/djreimer/seekable_hash.png)](https://codeclimate.com/github/djreimer/seekable_hash)
4
+
5
+ A simple Ruby gem for looking up values in deeply-nested hashes.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'seekable_hash'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install seekable_hash
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ hash = {
25
+ "foo" => {
26
+ "bar" => {
27
+ "baz" => "boot"
28
+ }
29
+ }
30
+ }
31
+
32
+ sh = SeekableHash[hash]
33
+
34
+ sh.seek("foo", "bar", "baz")
35
+ #=> "boot"
36
+
37
+ sh.seek("boot")
38
+ #=> nil
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/djreimer/seekable_hash/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "lib"
7
+ t.pattern = "test/**/*_test.rb"
8
+ t.verbose = true
9
+ end
10
+
11
+ desc "Run tests"
12
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ class SeekableHash < Hash
2
+ def seek(*args)
3
+ args.inject(self) do |hash, key|
4
+ hash.is_a?(Hash) ? hash[key] : nil
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'seekable_hash'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "seekable_hash"
8
+ spec.version = "1.0.0"
9
+ spec.authors = ["Derrick Reimer"]
10
+ spec.email = ["derrickreimer@gmail.com"]
11
+ spec.summary = %q{Hash + #seek}
12
+ spec.description = %q{A simple gem for looking up values in deeply-nested hashes}
13
+ spec.homepage = "https://github.com/djreimer/seekable_hash"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ describe SeekableHash do
4
+ it "should lookup deep values" do
5
+ hash = SeekableHash["foo" => { "bar" => "baz" }]
6
+ hash.seek("foo").must_equal("bar" => "baz")
7
+ hash.seek("foo", "bar").must_equal "baz"
8
+ end
9
+
10
+ it "should return nil when a key returns a non-hash value" do
11
+ hash = SeekableHash["foo" => { "bar" => "baz" }]
12
+ hash.seek("foo", "bar", "baz").must_equal nil
13
+ end
14
+
15
+ it "should return nil when a key is missing" do
16
+ hash = SeekableHash["foo" => { "bar" => "baz" }]
17
+ hash.seek("foo", "boot").must_equal nil
18
+ hash.seek("foo", "boot", "bar").must_equal nil
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'seekable_hash'
3
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seekable_hash
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Derrick Reimer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A simple gem for looking up values in deeply-nested hashes
42
+ email:
43
+ - derrickreimer@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - .travis.yml
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/seekable_hash.rb
55
+ - seekable_hash.gemspec
56
+ - test/seekable_hash_test.rb
57
+ - test/test_helper.rb
58
+ homepage: https://github.com/djreimer/seekable_hash
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.3.0
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: 'Hash + #seek'
82
+ test_files:
83
+ - test/seekable_hash_test.rb
84
+ - test/test_helper.rb