dig_bang 0.1.0 → 0.2.1

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0670b0608e058cc4cdd4fa0e9e33ee6aab6eac40
4
- data.tar.gz: 35e39edef75118cadb0c38b9f7cecb1201534053
3
+ metadata.gz: ebc5c1f2850d635c4e2fdf7cfff229403421f6f6
4
+ data.tar.gz: 13a010315ff0a96aaabafa35e8c7a7e26102dc7f
5
5
  SHA512:
6
- metadata.gz: d0092894ee96a06373a66732cd3a9b50dd8b537341320e66908e2a9481a415b80f466e6f745730e1d63b845f287064cc23352cca7c90c57e5f3ad10413edadef
7
- data.tar.gz: 718d9ca131b429717631953bab35dcbffb2b1a040cabacad4d585ba70bda1d2f714ddf6b0304a7fc8c36e926c6cc520fd08afe6a6999a7f2bc530d1471987051
6
+ metadata.gz: 9134f6bf470c9ac58b86b396a03da9db25093402453e0e5ea2a09fb90e6becf8134c3d5ece4b37a0d83690b368f22769097762092743089bf7e0e8330723f8c0
7
+ data.tar.gz: 569e6b567ae60641162acb3384aa9a8785c430e955c95447e76d5b2b1dbeee19e6642931fff0884d6db2ceef0f6fae4f62d544b52ca92bb1038078c5964c0ecc
@@ -0,0 +1 @@
1
+ 2.2.4
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.3
3
+ - 2.2.5
4
+ - 2.3.1
4
5
  before_install: gem install bundler -v 1.11.2
data/README.md CHANGED
@@ -1,9 +1,24 @@
1
1
  # DigBang
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dig_bang`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Here’s `Hash#dig!` and `Array#dig!`. They're similar to Ruby 2.3’s `Hash#dig` and `Array#dig`, but raise an exception instead of returning nil when a key isn’t found.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
5
 
6
+ ```ruby
7
+ places = { world: { uk: true } }
8
+
9
+ places.dig :world, :uk # true
10
+ places.dig! :world, :uk # true
11
+
12
+ places.dig :world, :uk, :bvi # nil
13
+ places.dig! :world, :uk, :bvi # KeyError: Key not found: :bvi
14
+ ```
15
+
16
+ ## dig is to #[] as #dig! is to #fetch
17
+
18
+ Ruby 2.3 introduces the new Hash#dig method for safe extraction of a nested value. It’s the equivalent of a safely repeated Hash#[].
19
+
20
+ #dig!, on the other hand, is the equivalent of a safely repeated Hash#fetch. It’s “safely unsafe”😉 raising the appropriate KeyError anywhere down the line, or returning the value if it exists.
21
+
7
22
  ## Installation
8
23
 
9
24
  Add this line to your application's Gemfile:
@@ -20,22 +35,3 @@ Or install it yourself as:
20
35
 
21
36
  $ gem install dig_bang
22
37
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dig_bang.
36
-
37
-
38
- ## License
39
-
40
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
-
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.homepage = 'https://github.com/dogweather/digbang'
19
19
  spec.license = 'MIT'
20
20
 
21
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features)/}) }
22
22
  spec.bindir = 'exe'
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
@@ -1,5 +1,18 @@
1
- require 'dig_bang/version'
2
-
1
+ # frozen_string_literal: true
3
2
  module DigBang
4
- # Your code goes here...
3
+ def self.fetch_all(fetchable, keys)
4
+ keys.reduce(fetchable) { |a, e| a.fetch(e) }
5
+ end
6
+ end
7
+
8
+ class Hash
9
+ def dig!(*keys)
10
+ DigBang.fetch_all(self, keys)
11
+ end
12
+ end
13
+
14
+ class Array
15
+ def dig!(*keys)
16
+ DigBang.fetch_all(self, keys)
17
+ end
5
18
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module DigBang
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.1'.freeze
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dig_bang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-16 00:00:00.000000000 Z
11
+ date: 2016-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,7 +62,7 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - ".gitignore"
65
- - ".rspec"
65
+ - ".ruby-version"
66
66
  - ".travis.yml"
67
67
  - Gemfile
68
68
  - LICENSE.txt
@@ -93,9 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  requirements: []
95
95
  rubyforge_project:
96
- rubygems_version: 2.5.0
96
+ rubygems_version: 2.6.4
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: 'Like #dig but raises an exception for key not found.'
100
100
  test_files: []
101
- has_rdoc:
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color