dig_bang 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +2 -1
- data/README.md +17 -21
- data/dig_bang.gemspec +1 -1
- data/lib/dig_bang.rb +16 -3
- data/lib/dig_bang/version.rb +1 -1
- metadata +4 -5
- data/.rspec +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebc5c1f2850d635c4e2fdf7cfff229403421f6f6
|
4
|
+
data.tar.gz: 13a010315ff0a96aaabafa35e8c7a7e26102dc7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9134f6bf470c9ac58b86b396a03da9db25093402453e0e5ea2a09fb90e6becf8134c3d5ece4b37a0d83690b368f22769097762092743089bf7e0e8330723f8c0
|
7
|
+
data.tar.gz: 569e6b567ae60641162acb3384aa9a8785c430e955c95447e76d5b2b1dbeee19e6642931fff0884d6db2ceef0f6fae4f62d544b52ca92bb1038078c5964c0ecc
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.4
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,24 @@
|
|
1
1
|
# DigBang
|
2
2
|
|
3
|
-
|
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
|
-
|
data/dig_bang.gemspec
CHANGED
@@ -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{^(
|
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']
|
data/lib/dig_bang.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
3
2
|
module DigBang
|
4
|
-
|
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
|
data/lib/dig_bang/version.rb
CHANGED
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
|
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-
|
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
|
-
- ".
|
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.
|
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