dig_exact 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36e453d8e742e7e072466751c7c58caad48b9326
4
+ data.tar.gz: 1431f086a91298d60ce05fa9859b8203affa8757
5
+ SHA512:
6
+ metadata.gz: c57709653463660252f82a6e6a284a954f21794f84bf736b1912c761b1161653ad7d96a66fe0ab8dc05ca6f4b3c16a9f1b4b0ff0ecc46c2721e89faa328604ef
7
+ data.tar.gz: 14100c3b4bf8b4f7c5db8e4e01a811c7f4fd71e070d6098d6858820269d0414f03f88a09bd4abe0ac301d244865457e85e37ca8b8c9b79dc6b8d686c60fbaf67
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ - 2.1.8
5
+ - 2.0.0-p648
6
+ - jruby-9.0.4.0
7
+ - jruby-1.7.23
8
+ - 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Jonathan Rochkind
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # dig_exact based on Dig_rb
2
+
3
+ `#dig_exact` is the same as `#dig`, but `#dig_exact` never raise `<Klass> does not have #dig method`, it will return nil instead.
4
+
5
+ [Our travis](https://travis-ci.org/jrochkind/dig_rb)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dig_exact'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dig_exact
22
+
23
+ ## Usage
24
+
25
+ * [Hash](http://ruby-doc.org/core-2.3.0/Hash.html#method-i-dig)
26
+ * [Array](http://ruby-doc.org/core-2.3.0/Array.html#method-i-dig)
27
+ * [Struct](http://ruby-doc.org/core-2.3.0/Struct.html#method-i-dig)
28
+ * [OpenStruct](http://ruby-doc.org/stdlib-2.3.0/libdoc/ostruct/rdoc/OpenStruct.html#method-i-dig)
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it ( https://github.com/jrochkind/dig_rb/fork )
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/test*.rb'] + FileList['test/**/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => [:test]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dig_exact"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/dig_exact.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dig_exact/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dig_exact"
8
+ spec.version = DigExact::VERSION
9
+ spec.authors = ["fangxing"]
10
+ spec.email = ["fangxing204@gmail.com"]
11
+
12
+ spec.summary = %q{#dig_exact return nil instead of raise Klass does not have #dig method TypeError}
13
+ spec.homepage = "https://github.com/fffx/dig_exact"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ #spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake", "~> 12"
23
+ spec.add_development_dependency "minitest", "~> 5.11"
24
+ end
@@ -0,0 +1,9 @@
1
+
2
+ Array.class_eval do
3
+ def dig_exact(key, *args)
4
+ value = self.at(key)
5
+ return value if args.length == 0
6
+ return nil unless value.respond_to? :dig_exact
7
+ value.dig_exact(*args)
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ Hash.class_eval do
2
+ def dig_exact(key, *args)
3
+ value = self[key]
4
+ return value if args.length == 0
5
+ return nil unless value.respond_to? :dig_exact
6
+ value.dig_exact(*args)
7
+ end
8
+ end
@@ -0,0 +1,18 @@
1
+ require 'ostruct'
2
+
3
+ OpenStruct.class_eval do
4
+ def dig_exact(name, *args)
5
+ begin
6
+ name = name.to_sym
7
+ rescue NoMethodError
8
+ raise TypeError, "#{name} is not a symbol nor a string"
9
+ end
10
+ return nil unless self.respond_to?(name)
11
+ value = self.send(name)
12
+
13
+ return value if args.length == 0
14
+ return nil unless value.respond_to? :dig_exact
15
+
16
+ value.dig_exact(*args)
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ Struct.class_eval do
2
+ def dig_exact(key, *args)
3
+ value = if key.respond_to?(:to_sym)
4
+ return nil unless self.respond_to?(key.to_sym)
5
+ self.send(key.to_sym)
6
+ elsif key.respond_to?(:to_int)
7
+ return nil unless self.length >= key.to_int + 1
8
+ self[key.to_int]
9
+ else
10
+ raise TypeError, "no implicit conversion of #{key.class} into Integer"
11
+ end
12
+
13
+ return value if args.length == 0
14
+ return nil unless value.respond_to? :dig_exact
15
+ value.dig_exact(*args)
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module DigExact
2
+ VERSION = "0.1"
3
+ end
data/lib/dig_exact.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'dig_exact/version'
2
+ require 'dig_exact/hash'
3
+ require 'dig_exact/array'
4
+ require 'dig_exact/struct'
5
+ require 'dig_exact/ostruct'
6
+
7
+ module DigExact
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dig_exact
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - fangxing
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.11'
41
+ description:
42
+ email:
43
+ - fangxing204@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
+ - bin/console
55
+ - bin/setup
56
+ - dig_exact.gemspec
57
+ - lib/dig_exact.rb
58
+ - lib/dig_exact/array.rb
59
+ - lib/dig_exact/hash.rb
60
+ - lib/dig_exact/ostruct.rb
61
+ - lib/dig_exact/struct.rb
62
+ - lib/dig_exact/version.rb
63
+ homepage: https://github.com/fffx/dig_exact
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.6.14
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: "#dig_exact return nil instead of raise Klass does not have #dig method TypeError"
87
+ test_files: []