respond_to_dig 1.0.0 → 1.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 +4 -4
 - data/.editorconfig +10 -0
 - data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
 - data/.gitignore +4 -0
 - data/.travis.yml +6 -0
 - data/README.md +3 -2
 - data/lib/respond_to_dig/version.rb +1 -1
 - data/lib/respond_to_dig.rb +7 -4
 - data/respond_to_dig.gemspec +2 -2
 - data/test/respond_to_dig_test.rb +18 -9
 - metadata +16 -13
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 38f3df9283b99bb984df4903b5cbf3c9918eafd3
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 4fda9b0c7ad5aa7a33e0f75c872e01714a2e4f64
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 70ed1d747efffcf96b38ba3e70c1fb3730b09e5466fc72f591f964675ab098c925d8ce8b63c55ad7b8112f451cae5190f2c2ec632288865445c245baecfa2da7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: c5ef4ceee329deaf2317936992287be1aced7310256a18c61f1ecca5113ee3cc61558cae4222e05fcf709c09f98713d542d4a98ca89d09fdf46107882f2e0487
         
     | 
    
        data/.editorconfig
    ADDED
    
    
| 
         @@ -0,0 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            | Q             | A
         
     | 
| 
      
 2 
     | 
    
         
            +
            | ------------- | ---
         
     | 
| 
      
 3 
     | 
    
         
            +
            | Branch?       | "master" for new features / 1.0 for fixes
         
     | 
| 
      
 4 
     | 
    
         
            +
            | Bug fix?      | yes/no
         
     | 
| 
      
 5 
     | 
    
         
            +
            | New feature?  | yes/no
         
     | 
| 
      
 6 
     | 
    
         
            +
            | BC breaks?    | yes/no
         
     | 
| 
      
 7 
     | 
    
         
            +
            | Deprecations? | yes/no
         
     | 
| 
      
 8 
     | 
    
         
            +
            | Tests pass?   | yes/no
         
     | 
| 
      
 9 
     | 
    
         
            +
            | Fixed tickets | comma-separated list of tickets fixed by the PR, if any
         
     | 
| 
      
 10 
     | 
    
         
            +
            | License       | MIT
         
     | 
| 
      
 11 
     | 
    
         
            +
            | Doc PR        | reference to the documentation PR, if any
         
     | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -5,8 +5,9 @@ RespondToDig 
     | 
|
| 
       5 
5 
     | 
    
         | 
| 
       6 
6 
     | 
    
         
             
            This gem backports Array#dig and Hash#dig methods from Ruby 2.3+ to earlier versions of Ruby, only if you explicitly call it.
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
            ## vs RubyDig
         
     | 
| 
       9 
     | 
    
         
            -
            *  
     | 
| 
      
 8 
     | 
    
         
            +
            ## vs [RubyDig](https://github.com/Invoca/ruby_dig)
         
     | 
| 
      
 9 
     | 
    
         
            +
            * RubyDig has side-effects, but RespondToDig doesn't.
         
     | 
| 
      
 10 
     | 
    
         
            +
            * RespondToDig only supports `Array` and `Hash`, but RespondToDig supports any `Enumerable` classes which have `[]` method such as `Struct`.
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
12 
     | 
    
         
             
            ## Installation
         
     | 
| 
       12 
13 
     | 
    
         | 
    
        data/lib/respond_to_dig.rb
    CHANGED
    
    | 
         @@ -1,15 +1,18 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module RespondToDig
         
     | 
| 
       2 
     | 
    
         
            -
              RESPONDERS = [Array, Hash]
         
     | 
| 
       3 
2 
     | 
    
         | 
| 
       4 
3 
     | 
    
         
             
              class << self
         
     | 
| 
       5 
4 
     | 
    
         
             
                def respond_to_dig(receiver)
         
     | 
| 
       6 
5 
     | 
    
         
             
                  receiver.tap do |r|
         
     | 
| 
       7 
     | 
    
         
            -
                    r.singleton_class.send(:include, RespondToDig) if RespondToDig. 
     | 
| 
      
 6 
     | 
    
         
            +
                    r.singleton_class.send(:include, RespondToDig) if RespondToDig.diggable? r
         
     | 
| 
       8 
7 
     | 
    
         
             
                  end
         
     | 
| 
       9 
8 
     | 
    
         
             
                end
         
     | 
| 
       10 
9 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
                # The reason why not purely duck typed by `[]` method is to avoid unexpected behavior,
         
     | 
| 
      
 11 
     | 
    
         
            +
                # for example we won't get `'o'` by `'foo'.dig(1)` by String#[].
         
     | 
| 
      
 12 
     | 
    
         
            +
                def diggable?(target)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  target.is_a? Enumerable and
         
     | 
| 
      
 14 
     | 
    
         
            +
                      target.respond_to? :[] and
         
     | 
| 
      
 15 
     | 
    
         
            +
                      not target.respond_to? :dig
         
     | 
| 
       13 
16 
     | 
    
         
             
                end
         
     | 
| 
       14 
17 
     | 
    
         
             
              end
         
     | 
| 
       15 
18 
     | 
    
         | 
    
        data/respond_to_dig.gemspec
    CHANGED
    
    | 
         @@ -6,9 +6,9 @@ require 'respond_to_dig/version' 
     | 
|
| 
       6 
6 
     | 
    
         
             
            Gem::Specification.new do |spec|
         
     | 
| 
       7 
7 
     | 
    
         
             
              spec.name          = "respond_to_dig"
         
     | 
| 
       8 
8 
     | 
    
         
             
              spec.version       = RespondToDig::VERSION
         
     | 
| 
       9 
     | 
    
         
            -
              spec.authors       = [" 
     | 
| 
      
 9 
     | 
    
         
            +
              spec.authors       = ["ymkjp"]
         
     | 
| 
       10 
10 
     | 
    
         
             
              spec.email         = ["ymkjp@jaist.ac.jp"]
         
     | 
| 
       11 
     | 
    
         
            -
              spec.summary       = %q{ 
     | 
| 
      
 11 
     | 
    
         
            +
              spec.summary       = %q{Explicit backporting of Array#dig and Hash#dig for Ruby < 2.3.}
         
     | 
| 
       12 
12 
     | 
    
         
             
              spec.homepage      = "https://github.com/announce/respond_to_dig"
         
     | 
| 
       13 
13 
     | 
    
         
             
              spec.license       = "MIT"
         
     | 
| 
       14 
14 
     | 
    
         | 
    
        data/test/respond_to_dig_test.rb
    CHANGED
    
    | 
         @@ -25,6 +25,10 @@ class RespondToDigTest 
     | 
|
| 
       25 
25 
     | 
    
         
             
                let (:a_nested_hash) {
         
     | 
| 
       26 
26 
     | 
    
         
             
                  RespondToDig::respond_to_dig({mom: {first: "Marge", last: "Bouvier"}, dad: {first: "Homer", last: "Simpson"}})
         
     | 
| 
       27 
27 
     | 
    
         
             
                }
         
     | 
| 
      
 28 
     | 
    
         
            +
                let (:containing_struct) {
         
     | 
| 
      
 29 
     | 
    
         
            +
                  Dog = Struct.new(:name, :age)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  RespondToDig::respond_to_dig({dogs: [Dog.new("Fred", 5), Dog.new("Harry", 2)]})
         
     | 
| 
      
 31 
     | 
    
         
            +
                }
         
     | 
| 
       28 
32 
     | 
    
         | 
| 
       29 
33 
     | 
    
         
             
                describe "Array" do
         
     | 
| 
       30 
34 
     | 
    
         
             
                  it "digs an array by index" do
         
     | 
| 
         @@ -47,10 +51,6 @@ class RespondToDigTest 
     | 
|
| 
       47 
51 
     | 
    
         
             
                    assert_raises(TypeError) { an_array.dig(:four) }
         
     | 
| 
       48 
52 
     | 
    
         
             
                  end
         
     | 
| 
       49 
53 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
                  it "digs into any object that implements dig" do
         
     | 
| 
       51 
     | 
    
         
            -
                    assert_equal [:a, :b], RespondToDig::respond_to_dig([0, Diggable.new]).dig(1, :a, :b)
         
     | 
| 
       52 
     | 
    
         
            -
                  end
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
54 
     | 
    
         
             
                  it "returns the value false" do
         
     | 
| 
       55 
55 
     | 
    
         
             
                    assert_equal false, a_nested_array.dig(1, 3)
         
     | 
| 
       56 
56 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -82,11 +82,20 @@ class RespondToDigTest 
     | 
|
| 
       82 
82 
     | 
    
         
             
                  end
         
     | 
| 
       83 
83 
     | 
    
         
             
                end
         
     | 
| 
       84 
84 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
                describe " 
     | 
| 
       86 
     | 
    
         
            -
                  it "navigates both" do
         
     | 
| 
       87 
     | 
    
         
            -
                    assert_equal 'Lisa', RespondToDig::respond_to_dig( 
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
                describe "Various classes" do
         
     | 
| 
      
 86 
     | 
    
         
            +
                  it "navigates both nested Hash and Array" do
         
     | 
| 
      
 87 
     | 
    
         
            +
                    assert_equal 'Lisa', RespondToDig::respond_to_dig(
         
     | 
| 
      
 88 
     | 
    
         
            +
                      {mom: {first: "Marge", last: "Bouvier"},
         
     | 
| 
      
 89 
     | 
    
         
            +
                       dad: {first: "Homer", last: "Simpson"},
         
     | 
| 
      
 90 
     | 
    
         
            +
                       kids: [{first: "Bart"}, {first: "Lisa"}]}).dig(:kids, 1, :first)
         
     | 
| 
      
 91 
     | 
    
         
            +
                  end
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
                  it "digs into any object that implements dig" do
         
     | 
| 
      
 94 
     | 
    
         
            +
                    assert_equal [:a, :b], RespondToDig::respond_to_dig([0, Diggable.new]).dig(1, :a, :b)
         
     | 
| 
      
 95 
     | 
    
         
            +
                  end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                  it "digs into Enumerable object that implements #[]" do
         
     | 
| 
      
 98 
     | 
    
         
            +
                    assert_equal 'Harry', RespondToDig::respond_to_dig(containing_struct).dig(:dogs, 1, :name)
         
     | 
| 
       90 
99 
     | 
    
         
             
                  end
         
     | 
| 
       91 
100 
     | 
    
         
             
                end
         
     | 
| 
       92 
101 
     | 
    
         
             
              end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,10 +1,10 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: respond_to_dig
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
     | 
    
         
            -
            -  
     | 
| 
      
 7 
     | 
    
         
            +
            - ymkjp
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
         @@ -14,42 +14,42 @@ dependencies: 
     | 
|
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
       15 
15 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       16 
16 
     | 
    
         
             
                requirements:
         
     | 
| 
       17 
     | 
    
         
            -
                - - ~>
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       18 
18 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       19 
19 
     | 
    
         
             
                    version: '1.7'
         
     | 
| 
       20 
20 
     | 
    
         
             
              type: :development
         
     | 
| 
       21 
21 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       22 
22 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       23 
23 
     | 
    
         
             
                requirements:
         
     | 
| 
       24 
     | 
    
         
            -
                - - ~>
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       25 
25 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       26 
26 
     | 
    
         
             
                    version: '1.7'
         
     | 
| 
       27 
27 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       28 
28 
     | 
    
         
             
              name: rake
         
     | 
| 
       29 
29 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       30 
30 
     | 
    
         
             
                requirements:
         
     | 
| 
       31 
     | 
    
         
            -
                - - ~>
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       32 
32 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       33 
33 
     | 
    
         
             
                    version: '10.0'
         
     | 
| 
       34 
34 
     | 
    
         
             
              type: :development
         
     | 
| 
       35 
35 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       36 
36 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       37 
37 
     | 
    
         
             
                requirements:
         
     | 
| 
       38 
     | 
    
         
            -
                - - ~>
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
       39 
39 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       40 
40 
     | 
    
         
             
                    version: '10.0'
         
     | 
| 
       41 
41 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       42 
42 
     | 
    
         
             
              name: minitest
         
     | 
| 
       43 
43 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       44 
44 
     | 
    
         
             
                requirements:
         
     | 
| 
       45 
     | 
    
         
            -
                - -  
     | 
| 
      
 45 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       46 
46 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       47 
47 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       48 
48 
     | 
    
         
             
              type: :development
         
     | 
| 
       49 
49 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       50 
50 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       51 
51 
     | 
    
         
             
                requirements:
         
     | 
| 
       52 
     | 
    
         
            -
                - -  
     | 
| 
      
 52 
     | 
    
         
            +
                - - ">="
         
     | 
| 
       53 
53 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       54 
54 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       55 
55 
     | 
    
         
             
            description: 
         
     | 
| 
         @@ -59,7 +59,10 @@ executables: [] 
     | 
|
| 
       59 
59 
     | 
    
         
             
            extensions: []
         
     | 
| 
       60 
60 
     | 
    
         
             
            extra_rdoc_files: []
         
     | 
| 
       61 
61 
     | 
    
         
             
            files:
         
     | 
| 
       62 
     | 
    
         
            -
            - . 
     | 
| 
      
 62 
     | 
    
         
            +
            - ".editorconfig"
         
     | 
| 
      
 63 
     | 
    
         
            +
            - ".github/PULL_REQUEST_TEMPLATE.md"
         
     | 
| 
      
 64 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
      
 65 
     | 
    
         
            +
            - ".travis.yml"
         
     | 
| 
       63 
66 
     | 
    
         
             
            - CONTRIBUTING.md
         
     | 
| 
       64 
67 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       65 
68 
     | 
    
         
             
            - LICENSE.txt
         
     | 
| 
         @@ -79,19 +82,19 @@ require_paths: 
     | 
|
| 
       79 
82 
     | 
    
         
             
            - lib
         
     | 
| 
       80 
83 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       81 
84 
     | 
    
         
             
              requirements:
         
     | 
| 
       82 
     | 
    
         
            -
              - -  
     | 
| 
      
 85 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       83 
86 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       84 
87 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       85 
88 
     | 
    
         
             
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
       86 
89 
     | 
    
         
             
              requirements:
         
     | 
| 
       87 
     | 
    
         
            -
              - -  
     | 
| 
      
 90 
     | 
    
         
            +
              - - ">="
         
     | 
| 
       88 
91 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       89 
92 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       90 
93 
     | 
    
         
             
            requirements: []
         
     | 
| 
       91 
94 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       92 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 95 
     | 
    
         
            +
            rubygems_version: 2.2.2
         
     | 
| 
       93 
96 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       94 
97 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       95 
     | 
    
         
            -
            summary:  
     | 
| 
      
 98 
     | 
    
         
            +
            summary: Explicit backporting of Array#dig and Hash#dig for Ruby < 2.3.
         
     | 
| 
       96 
99 
     | 
    
         
             
            test_files:
         
     | 
| 
       97 
100 
     | 
    
         
             
            - test/respond_to_dig_test.rb
         
     |