pattern_query_helper 0.1.9 → 0.1.10
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/Gemfile.lock +1 -1
- data/lib/pattern_query_helper/filtering.rb +0 -4
- data/lib/pattern_query_helper/version.rb +1 -1
- data/lib/pattern_query_helper.rb +1 -35
- 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: b868a9d24784bf1635be621ee9ab43542f176774
         | 
| 4 | 
            +
              data.tar.gz: e1595a029ff272c8c7fc8dfe872615b672ab40dc
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 267714428ec883cd37a8879ae59ca3442fbd20296012575d3b5cb84796535f6a22f74d14fa93ab56ff0bf1c97dff1bfb04d32f7c9eeba2c30285d2bb7955cd79
         | 
| 7 | 
            +
              data.tar.gz: 0f84d630e8e6c7174b80135cb6a5e27a22f519d18131ca148545278f38e64abb97f1faa6a0a7b9a0e80593480863e118fe1d578aaf133299510703eeae42e0a5
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
    
        data/lib/pattern_query_helper.rb
    CHANGED
    
    | @@ -18,13 +18,7 @@ module PatternQueryHelper | |
| 18 18 | 
             
              end
         | 
| 19 19 |  | 
| 20 20 | 
             
              def self.run_active_record_query(active_record_call, query_helpers, single_record=false)
         | 
| 21 | 
            -
                 | 
| 22 | 
            -
                  single_record_active_record_query(active_record_call, query_helpers)
         | 
| 23 | 
            -
                elsif query_helpers[:per_page] || query_helpers[:page]
         | 
| 24 | 
            -
                  paginated_active_record_query(active_record_call, query_helpers)
         | 
| 25 | 
            -
                else
         | 
| 26 | 
            -
                  active_record_query(active_record_call, query_helpers)
         | 
| 27 | 
            -
                end
         | 
| 21 | 
            +
                run_sql_query(active_record_call.model, active_record_call.to_sql, {}, query_helpers, single_record)
         | 
| 28 22 | 
             
              end
         | 
| 29 23 |  | 
| 30 24 | 
             
              private
         | 
| @@ -94,34 +88,6 @@ module PatternQueryHelper | |
| 94 88 | 
             
                }
         | 
| 95 89 | 
             
              end
         | 
| 96 90 |  | 
| 97 | 
            -
              def self.active_record_query(active_record_call, query_helpers)
         | 
| 98 | 
            -
                query_helpers = parse_helpers(query_helpers)
         | 
| 99 | 
            -
                filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call, query_helpers[:filters])
         | 
| 100 | 
            -
                sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call, query_helpers[:sorting])
         | 
| 101 | 
            -
                with_associations = PatternQueryHelper::Associations.load_associations(sorted_query, query_helpers[:associations])
         | 
| 102 | 
            -
                {
         | 
| 103 | 
            -
                  data: with_associations
         | 
| 104 | 
            -
                }
         | 
| 105 | 
            -
              end
         | 
| 106 | 
            -
             | 
| 107 | 
            -
              def self.paginated_active_record_query(active_record_call, query_helpers)
         | 
| 108 | 
            -
                query_helpers = parse_helpers(query_helpers)
         | 
| 109 | 
            -
                filtered_query = PatternQueryHelper::Filtering.filter_active_record_query(active_record_call, query_helpers[:filters])
         | 
| 110 | 
            -
                sorted_query = PatternQueryHelper::Sorting.sort_active_record_query(active_record_call, query_helpers[:sorting])
         | 
| 111 | 
            -
                paginated_query = PatternQueryHelper::Pagination.paginate_active_record_query(sorted_query, query_helpers[:pagination])
         | 
| 112 | 
            -
                with_associations = PatternQueryHelper::Associations.load_associations(paginated_query, query_helpers[:associations])
         | 
| 113 | 
            -
                count = ActiveRecord::Base.connection.execute(%{with query as (#{sorted_query.to_sql}) select count(*) as count from query}).first["count"].to_i
         | 
| 114 | 
            -
                pagination = PatternQueryHelper::Pagination.create_pagination_payload(count, query_helpers[:pagination])
         | 
| 115 | 
            -
                {
         | 
| 116 | 
            -
                  pagination: pagination,
         | 
| 117 | 
            -
                  data: with_associations
         | 
| 118 | 
            -
                }
         | 
| 119 | 
            -
              end
         | 
| 120 | 
            -
             | 
| 121 | 
            -
              def self.single_record_active_record_query(active_record_call, query_helpers)
         | 
| 122 | 
            -
                # TODO: Add Logic to this method
         | 
| 123 | 
            -
              end
         | 
| 124 | 
            -
             | 
| 125 91 | 
             
              def self.parse_helpers(params)
         | 
| 126 92 | 
             
                filtering = PatternQueryHelper::Filtering.create_filters(params[:filter])
         | 
| 127 93 | 
             
                sorting = PatternQueryHelper::Sorting.parse_sorting_params(params[:sort])
         |