dense 1.1.4 → 1.1.5
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/CHANGELOG.md +5 -0
 - data/lib/dense.rb +1 -1
 - data/lib/dense/methods.rb +37 -17
 - data/lib/dense/path.rb +1 -1
 - metadata +3 -3
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: cfc698913c3d5e9fcc87f8af83dea003df39e71d
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a81ecccdad7be0875a560025022b00c28b97558a
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 332efedf4c5fe21336898ff830f90dda169a3fce2da5984b553e9ca61c8d5bd855e3e62bf40e403286f66ed922212928ee46209a9dedbc187079b4af97608270
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 5b4806c891b739b277c2c7447b232d3c9a0d974c1aea8ea5749541f5bbd77a85ec0f3aa70d27217161ff7ddde1b637969721a57a099400792509373cd20e9eaf
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/dense.rb
    CHANGED
    
    
    
        data/lib/dense/methods.rb
    CHANGED
    
    | 
         @@ -12,22 +12,22 @@ module Dense; class << self 
     | 
|
| 
       12 
12 
     | 
    
         
             
              def fetch(o, path, default=::KeyError, &block)
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                pa = Dense::Path.make(path)
         
     | 
| 
       15 
     | 
    
         
            -
                 
     | 
| 
      
 15 
     | 
    
         
            +
                hits, misses = pa.gather(o).partition(&:first)
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                if  
     | 
| 
      
 17 
     | 
    
         
            +
                if hits.empty?
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                  return pa.narrow(
         
     | 
| 
       20 
     | 
    
         
            -
                     
     | 
| 
      
 20 
     | 
    
         
            +
                    misses.collect { |m| call_default_block(o, path, block, m) }
         
     | 
| 
       21 
21 
     | 
    
         
             
                  ) if block
         
     | 
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                  return pa.narrow(
         
     | 
| 
       24 
     | 
    
         
            -
                     
     | 
| 
      
 24 
     | 
    
         
            +
                    misses.collect { |m| default }
         
     | 
| 
       25 
25 
     | 
    
         
             
                  ) if default != KeyError
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
                  fail miss_error(path,  
     | 
| 
      
 27 
     | 
    
         
            +
                  fail miss_error(path, misses.first)
         
     | 
| 
       28 
28 
     | 
    
         
             
                end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
                pa.narrow( 
     | 
| 
      
 30 
     | 
    
         
            +
                pa.narrow(hits.collect { |e| e[2][e[3]] })
         
     | 
| 
       31 
31 
     | 
    
         
             
              end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
              def set(o, path, value)
         
     | 
| 
         @@ -35,7 +35,7 @@ module Dense; class << self 
     | 
|
| 
       35 
35 
     | 
    
         
             
                Dense::Path.make(path)
         
     | 
| 
       36 
36 
     | 
    
         
             
                  .gather(o)
         
     | 
| 
       37 
37 
     | 
    
         
             
                  .each { |hit|
         
     | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
      
 38 
     | 
    
         
            +
                    validate(path, hit) if hit[0] == false
         
     | 
| 
       39 
39 
     | 
    
         
             
                    hit[2][hit[3]] = value }
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                value
         
     | 
| 
         @@ -67,7 +67,7 @@ module Dense; class << self 
     | 
|
| 
       67 
67 
     | 
    
         
             
                  .each { |hit|
         
     | 
| 
       68 
68 
     | 
    
         
             
                    if hit[0] == false
         
     | 
| 
       69 
69 
     | 
    
         
             
                      n = hit[4].first
         
     | 
| 
       70 
     | 
    
         
            -
                       
     | 
| 
      
 70 
     | 
    
         
            +
                      validate(path, hit) \
         
     | 
| 
       71 
71 
     | 
    
         
             
                        if n.nil? && ! key_matches_collection?(hit[3], hit[2])
         
     | 
| 
       72 
72 
     | 
    
         
             
                      hit[2][hit[3]] =
         
     | 
| 
       73 
73 
     | 
    
         
             
                        if n.is_a?(String)
         
     | 
| 
         @@ -87,7 +87,7 @@ module Dense; class << self 
     | 
|
| 
       87 
87 
     | 
    
         
             
                Dense::Path.make(path)
         
     | 
| 
       88 
88 
     | 
    
         
             
                  .gather(o)
         
     | 
| 
       89 
89 
     | 
    
         
             
                  .each { |hit|
         
     | 
| 
       90 
     | 
    
         
            -
                     
     | 
| 
      
 90 
     | 
    
         
            +
                    validate(path, hit) if hit[0] == false
         
     | 
| 
       91 
91 
     | 
    
         
             
                    if hit[2].is_a?(Array)
         
     | 
| 
       92 
92 
     | 
    
         
             
                      hit[2].insert(hit[3], value)
         
     | 
| 
       93 
93 
     | 
    
         
             
                    else
         
     | 
| 
         @@ -149,15 +149,33 @@ module Dense; class << self 
     | 
|
| 
       149 
149 
     | 
    
         
             
                err
         
     | 
| 
       150 
150 
     | 
    
         
             
              end
         
     | 
| 
       151 
151 
     | 
    
         | 
| 
       152 
     | 
    
         
            -
               
     | 
| 
      
 152 
     | 
    
         
            +
              # IndexError:
         
     | 
| 
      
 153 
     | 
    
         
            +
              #   Raised when the given index is invalid.
         
     | 
| 
      
 154 
     | 
    
         
            +
              # KeyError:
         
     | 
| 
      
 155 
     | 
    
         
            +
              #   Raised when the specified key is not found. It is a subclass of IndexError.
         
     | 
| 
       153 
156 
     | 
    
         | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
                path2 = Dense::Path.make(miss[4]).to_s.inspect
         
     | 
| 
      
 157 
     | 
    
         
            +
              def index_error(path, miss)
         
     | 
| 
       156 
158 
     | 
    
         | 
| 
       157 
     | 
    
         
            -
                 
     | 
| 
       158 
     | 
    
         
            -
                msg = "#{msg} (#{path2} remains)" if path2 != '""'
         
     | 
| 
      
 159 
     | 
    
         
            +
                if miss[2].is_a?(Array) || miss[2].is_a?(Hash)
         
     | 
| 
       159 
160 
     | 
    
         | 
| 
       160 
     | 
    
         
            -
             
     | 
| 
      
 161 
     | 
    
         
            +
                  path1 = Dense::Path.make(miss[1] + [ miss[3] ]).to_s.inspect
         
     | 
| 
      
 162 
     | 
    
         
            +
                  path2 = Dense::Path.make(miss[4]).to_s.inspect
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                  msg = "found nothing at #{path1}"
         
     | 
| 
      
 165 
     | 
    
         
            +
                  msg = "#{msg} (#{path2} remains)" if path2 != '""'
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                  make_error(KeyError, msg, path, miss)
         
     | 
| 
      
 168 
     | 
    
         
            +
             
     | 
| 
      
 169 
     | 
    
         
            +
                else
         
     | 
| 
      
 170 
     | 
    
         
            +
             
     | 
| 
      
 171 
     | 
    
         
            +
                  path1 = Dense::Path.make(miss[1]).to_s.inspect
         
     | 
| 
      
 172 
     | 
    
         
            +
                  path2 = Dense::Path.make(miss[4]).to_s.inspect
         
     | 
| 
      
 173 
     | 
    
         
            +
             
     | 
| 
      
 174 
     | 
    
         
            +
                  msg = "found no collection at #{path1} for key #{miss[3].inspect}"
         
     | 
| 
      
 175 
     | 
    
         
            +
                  msg = "#{msg} (#{path2} remains)" if path2 != '""'
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                  make_error(IndexError, msg, path, miss)
         
     | 
| 
      
 178 
     | 
    
         
            +
                end
         
     | 
| 
       161 
179 
     | 
    
         
             
              end
         
     | 
| 
       162 
180 
     | 
    
         | 
| 
       163 
181 
     | 
    
         
             
              def type_error(path, miss)
         
     | 
| 
         @@ -174,16 +192,18 @@ module Dense; class << self 
     | 
|
| 
       174 
192 
     | 
    
         
             
                if miss[2].is_a?(Array) && ! miss[3].is_a?(Integer)
         
     | 
| 
       175 
193 
     | 
    
         
             
                  type_error(path, miss)
         
     | 
| 
       176 
194 
     | 
    
         
             
                else
         
     | 
| 
       177 
     | 
    
         
            -
                   
     | 
| 
      
 195 
     | 
    
         
            +
                  index_error(path, miss)
         
     | 
| 
       178 
196 
     | 
    
         
             
                end
         
     | 
| 
       179 
197 
     | 
    
         
             
              end
         
     | 
| 
       180 
198 
     | 
    
         | 
| 
       181 
     | 
    
         
            -
              def  
     | 
| 
      
 199 
     | 
    
         
            +
              def validate(path, miss)
         
     | 
| 
       182 
200 
     | 
    
         | 
| 
       183 
201 
     | 
    
         
             
                fail miss_error(path, miss) \
         
     | 
| 
       184 
202 
     | 
    
         
             
                  if miss[4].any?
         
     | 
| 
       185 
203 
     | 
    
         
             
                fail type_error(path, miss) \
         
     | 
| 
       186 
204 
     | 
    
         
             
                  if miss[2].is_a?(Array) && ! miss[2].is_a?(Integer)
         
     | 
| 
      
 205 
     | 
    
         
            +
             
     | 
| 
      
 206 
     | 
    
         
            +
                # else, no failure, carry on!
         
     | 
| 
       187 
207 
     | 
    
         
             
              end
         
     | 
| 
       188 
208 
     | 
    
         | 
| 
       189 
209 
     | 
    
         
             
              def call_default_block(o, path, block, miss)
         
     | 
    
        data/lib/dense/path.rb
    CHANGED
    
    | 
         @@ -295,7 +295,7 @@ class Dense::Path 
     | 
|
| 
       295 
295 
     | 
    
         
             
                  if k.nil?
         
     | 
| 
       296 
296 
     | 
    
         | 
| 
       297 
297 
     | 
    
         
             
            #puts RD + ind + "| 2-> " + [ false, path0[0..-2], data0, path0.last, path ].inspect unless data.is_a?(Array) || data.is_a?(Hash)
         
     | 
| 
       298 
     | 
    
         
            -
                return acc.push([ false, path0 
     | 
| 
      
 298 
     | 
    
         
            +
                return acc.push([ false, path0, data, path.first, path[1..-1] ]) \
         
     | 
| 
       299 
299 
     | 
    
         
             
                  unless data.is_a?(Array) || data.is_a?(Hash)
         
     | 
| 
       300 
300 
     | 
    
         | 
| 
       301 
301 
     | 
    
         
             
                return _dot_gather(depth, path0, data0, data, path[1..-1], acc) \
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: dense
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1.1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.1.5
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - John Mettraux
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2018- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2018-12-04 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: raabro
         
     | 
| 
         @@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       80 
80 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       81 
81 
     | 
    
         
             
            requirements: []
         
     | 
| 
       82 
82 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       83 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 83 
     | 
    
         
            +
            rubygems_version: 2.6.14.3
         
     | 
| 
       84 
84 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       85 
85 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       86 
86 
     | 
    
         
             
            summary: fetching deep in a dense structure
         
     |