looksist 0.2.0 → 0.2.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/lib/looksist/hashed.rb +21 -15
 - data/lib/looksist/version.rb +1 -1
 - 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: 6104d9b264565171b9c36c00f2ed77c92f032f1a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: d8b49f214f2e2a06a107597d14f430064f451c13
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 00c77002c2b385a4dcebe00cf88b63beab0e952c4561081c712cf2e556c39f060b716637d7bc590f0c5a80638124f5f3a67782a9167291f3d2a31b8060cbc13b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: e5fb28133d5630f8b2b0f1d52a8f9bdb7945d81876f4994204cb68d280f58060268e8053500b54a8c641994fa49cd6c6fbb24ece6cf996445260f41cc0760e71
         
     | 
    
        data/lib/looksist/hashed.rb
    CHANGED
    
    | 
         @@ -14,29 +14,28 @@ module Looksist 
     | 
|
| 
       14 
14 
     | 
    
         
             
                    @rules ||= {}
         
     | 
| 
       15 
15 
     | 
    
         
             
                    (@rules[after] ||= []) << opts
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
                     
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
                           
     | 
| 
       24 
     | 
    
         
            -
                             
     | 
| 
       25 
     | 
    
         
            -
             
     | 
| 
       26 
     | 
    
         
            -
                          end.to_hash.deep_symbolize_keys
         
     | 
| 
       27 
     | 
    
         
            -
                        else
         
     | 
| 
       28 
     | 
    
         
            -
                          inject_attributes_at(hash[opts[:at]], opts)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    unless @rules[after].length > 1
         
     | 
| 
      
 18 
     | 
    
         
            +
                      define_method("#{after}_with_inject") do |*args|
         
     | 
| 
      
 19 
     | 
    
         
            +
                        hash = send("#{after}_without_inject".to_sym, *args)
         
     | 
| 
      
 20 
     | 
    
         
            +
                        self.class.instance_variable_get(:@rules)[after].each do |opts|
         
     | 
| 
      
 21 
     | 
    
         
            +
                          if opts[:at].is_a? String
         
     | 
| 
      
 22 
     | 
    
         
            +
                            hash = update_using_json_path(hash, opts).to_hash.deep_symbolize_keys
         
     | 
| 
      
 23 
     | 
    
         
            +
                          else
         
     | 
| 
      
 24 
     | 
    
         
            +
                            inject_attributes_at(hash[opts[:at]], opts)
         
     | 
| 
      
 25 
     | 
    
         
            +
                          end
         
     | 
| 
       29 
26 
     | 
    
         
             
                        end
         
     | 
| 
      
 27 
     | 
    
         
            +
                        hash
         
     | 
| 
       30 
28 
     | 
    
         
             
                      end
         
     | 
| 
       31 
     | 
    
         
            -
                       
     | 
| 
      
 29 
     | 
    
         
            +
                      alias_method_chain after, :inject
         
     | 
| 
       32 
30 
     | 
    
         
             
                    end
         
     | 
| 
       33 
     | 
    
         
            -
                    alias_method_chain after, :inject
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
31 
     | 
    
         
             
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
       36 
34 
     | 
    
         
             
                end
         
     | 
| 
       37 
35 
     | 
    
         | 
| 
       38 
36 
     | 
    
         
             
                included do |base|
         
     | 
| 
       39 
37 
     | 
    
         
             
                  base.class_attribute :rules
         
     | 
| 
      
 38 
     | 
    
         
            +
                  base.rules = {}
         
     | 
| 
       40 
39 
     | 
    
         
             
                end
         
     | 
| 
       41 
40 
     | 
    
         | 
| 
       42 
41 
     | 
    
         
             
                private
         
     | 
| 
         @@ -50,6 +49,13 @@ module Looksist 
     | 
|
| 
       50 
49 
     | 
    
         
             
                  hash_offset
         
     | 
| 
       51 
50 
     | 
    
         
             
                end
         
     | 
| 
       52 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
                def update_using_json_path(hash, opts)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  JsonPath.for(hash.with_indifferent_access).gsub!(opts[:at]) do |i|
         
     | 
| 
      
 54 
     | 
    
         
            +
                    i.is_a?(Array) ? inject_attributes_for(i, opts) : inject_attributes_at(i, opts) unless i.empty?
         
     | 
| 
      
 55 
     | 
    
         
            +
                    i
         
     | 
| 
      
 56 
     | 
    
         
            +
                  end
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
       53 
59 
     | 
    
         
             
                def inject_attributes_for(arry_of_hashes, opts)
         
     | 
| 
       54 
60 
     | 
    
         
             
                  entity_name = __entity__(opts[:bucket_name] || opts[:using])
         
     | 
| 
       55 
61 
     | 
    
         
             
                  keys = (arry_of_hashes.collect { |i| i[opts[:using]] }).compact.uniq
         
     | 
    
        data/lib/looksist/version.rb
    CHANGED