json_paths 0.0.1 → 0.0.3
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/lib/json_paths/version.rb +1 -1
- data/lib/json_paths.rb +7 -7
- data/spec/json_paths_spec.rb +11 -9
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 82f2a9c9a57fa7ca49cf824acd9468fe1b0374c9
         | 
| 4 | 
            +
              data.tar.gz: 176584bdd7962d35e201867ace997c3931c3e9c6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: b7271ebdd4820f6e192b21d2ad966921fd1bcdfa53de52584f05e322662c5cc8735304482f66dfd3cdf6abb087a95ff24b710cd56ed0a13fe7b996c5cb797f91
         | 
| 7 | 
            +
              data.tar.gz: 11d70866d9e4e9638e6a7b8ec5bf25947d7c13af7c3c2162f2813832fbb0a35a2c3543c50219c937a567c721e31e43db3392b14229d19747d63b743c26938f7e
         | 
    
        data/lib/json_paths/version.rb
    CHANGED
    
    
    
        data/lib/json_paths.rb
    CHANGED
    
    | @@ -22,10 +22,10 @@ class JsonPaths | |
| 22 22 | 
             
                paths = []
         | 
| 23 23 |  | 
| 24 24 | 
             
                parsed_json.each_key do |key|
         | 
| 25 | 
            -
                  paths << key_to_path(parsed_json, key) | 
| 25 | 
            +
                  paths << key_to_path(parsed_json, key)
         | 
| 26 26 | 
             
                end
         | 
| 27 27 |  | 
| 28 | 
            -
                paths.flatten
         | 
| 28 | 
            +
                paths.flatten.map { |path| "$." + path }
         | 
| 29 29 | 
             
              end
         | 
| 30 30 |  | 
| 31 31 | 
             
              def key_to_path(hash, key)
         | 
| @@ -33,9 +33,9 @@ class JsonPaths | |
| 33 33 | 
             
                value = hash[key]
         | 
| 34 34 |  | 
| 35 35 | 
             
                if value.respond_to?(:keys)
         | 
| 36 | 
            -
                  value.each_key do |k|
         | 
| 37 | 
            -
                     | 
| 38 | 
            -
                  end
         | 
| 36 | 
            +
                  paths_for_key << value.each_key do |k|
         | 
| 37 | 
            +
                    key_to_path(value, k).map { |ktp| key + "." + ktp }
         | 
| 38 | 
            +
                  end.flatten
         | 
| 39 39 | 
             
                elsif value.respond_to?(:each_with_index)
         | 
| 40 40 | 
             
                  value.each_with_index do |v,i|
         | 
| 41 41 | 
             
                    paths_for_key << JsonPaths.new(v.to_json).paths.map do |j|
         | 
| @@ -43,9 +43,9 @@ class JsonPaths | |
| 43 43 | 
             
                    end
         | 
| 44 44 | 
             
                  end
         | 
| 45 45 | 
             
                else
         | 
| 46 | 
            -
                  paths_for_key  | 
| 46 | 
            +
                  paths_for_key << key.to_s
         | 
| 47 47 | 
             
                end
         | 
| 48 48 |  | 
| 49 | 
            -
                 | 
| 49 | 
            +
                paths_for_key
         | 
| 50 50 | 
             
              end
         | 
| 51 51 | 
             
            end
         | 
    
        data/spec/json_paths_spec.rb
    CHANGED
    
    | @@ -4,20 +4,22 @@ describe JsonPaths do | |
| 4 4 | 
             
              let(:json) do
         | 
| 5 5 | 
             
                <<-EOF
         | 
| 6 6 | 
             
                {
         | 
| 7 | 
            -
                  "a":  | 
| 8 | 
            -
                     | 
| 9 | 
            -
                      " | 
| 7 | 
            +
                  "a": [
         | 
| 8 | 
            +
                    {
         | 
| 9 | 
            +
                      "b": 1,
         | 
| 10 | 
            +
                      "c": 2
         | 
| 10 11 | 
             
                    },
         | 
| 11 | 
            -
                     | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 12 | 
            +
                    {
         | 
| 13 | 
            +
                      "d": 3
         | 
| 14 | 
            +
                    }
         | 
| 15 | 
            +
                  ]
         | 
| 14 16 | 
             
                }
         | 
| 15 17 | 
             
                EOF
         | 
| 16 18 | 
             
              end
         | 
| 17 19 |  | 
| 18 20 | 
             
              subject { JsonPaths.new(json) }
         | 
| 19 21 |  | 
| 20 | 
            -
              specify { expect(subject.paths).to include("$.a.b | 
| 21 | 
            -
              specify { expect(subject.paths).to include("$.a. | 
| 22 | 
            -
              specify { expect(subject.paths).to include("$.a | 
| 22 | 
            +
              specify { expect(subject.paths).to include("$.a[0].b") }
         | 
| 23 | 
            +
              specify { expect(subject.paths).to include("$.a[0].c") }
         | 
| 24 | 
            +
              specify { expect(subject.paths).to include("$.a[1].d") }
         | 
| 23 25 | 
             
            end
         |