query_methods_extend 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
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c1c09d9a5b6095985c753cae8723a064f231c8ad
         | 
| 4 | 
            +
              data.tar.gz: 51d97ba8f08c24129ddd7c43ff2ec35d0836f3d3
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 0e5a639e1397544856539f123a5a8a1fcce44bdf4557a8f53e067933bde27112180e9906f35f0ca225d23127bc4dd88f350373ecd408ab8852a97ddc4da27ddb
         | 
| 7 | 
            +
              data.tar.gz: f38a9b1a4cb249ea2f1fd0396b3aee65bb267c0204a44078f0f10add77b84d2d7622a72c9acbd1838639e5891f6dfa917f6d8d3349bdc8d4407dd2d5fee4f78f
         | 
| @@ -13,10 +13,32 @@ module QueryMethodsExtend | |
| 13 13 | 
             
                    association = self.try(:reflect_on_association, method_name)
         | 
| 14 14 | 
             
                    result = false
         | 
| 15 15 | 
             
                    if association && association.try(:macro) == :has_many
         | 
| 16 | 
            -
                       | 
| 17 | 
            -
             | 
| 18 | 
            -
                       | 
| 19 | 
            -
             | 
| 16 | 
            +
                      options = association.options
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                      if options[:through]
         | 
| 19 | 
            +
                        @check_association_exist_flag = false
         | 
| 20 | 
            +
                        return self.all.send(options[:through]).send(method_name)
         | 
| 21 | 
            +
                      end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                      query = self.select(association.active_record.primary_key)
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                      if options[:as] && !association.inverse_of && association.klass
         | 
| 26 | 
            +
                        polymorphic_as = association.klass.reflect_on_association(options[:as])
         | 
| 27 | 
            +
                        if polymorphic_as.polymorphic? && association.active_record
         | 
| 28 | 
            +
                          polymorphic_model = polymorphic_as.active_record
         | 
| 29 | 
            +
                          model = association.active_record
         | 
| 30 | 
            +
                          @check_association_exist_flag = false
         | 
| 31 | 
            +
                          return polymorphic_as.active_record
         | 
| 32 | 
            +
                            .where("#{polymorphic_model.table_name}.#{polymorphic_as.foreign_type}".to_sym => model.name)
         | 
| 33 | 
            +
                            .where("#{polymorphic_model.table_name}.#{polymorphic_as.foreign_key}".to_sym => query)
         | 
| 34 | 
            +
                        end
         | 
| 35 | 
            +
                      end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                      model = association.options[:class] || association.inverse_of.active_record
         | 
| 38 | 
            +
                      foreign_key = association.options[:foreign_key] || association.inverse_of.foreign_key
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                      result = model.where("#{model.table_name}.#{foreign_key.to_s}".to_sym => query)
         | 
| 41 | 
            +
             | 
| 20 42 | 
             
                    end
         | 
| 21 43 |  | 
| 22 44 | 
             
                    @check_association_exist_flag = false
         | 
| Binary file | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: query_methods_extend
         | 
| 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 | 
             
            - Alicuche
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2015-02- | 
| 11 | 
            +
            date: 2015-02-09 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activerecord
         | 
| @@ -121,6 +121,7 @@ files: | |
| 121 121 | 
             
            - lib/query_methods_extend/spec/union_spec.rb
         | 
| 122 122 | 
             
            - lib/query_methods_extend/union.rb
         | 
| 123 123 | 
             
            - lib/query_methods_extend/version.rb
         | 
| 124 | 
            +
            - query_methods_extend-1.0.0.gem
         | 
| 124 125 | 
             
            - query_methods_extend.gemspec
         | 
| 125 126 | 
             
            - spec/models/book.rb
         | 
| 126 127 | 
             
            - spec/models/category.rb
         |