Sha256: dc96f69d208a8a0fc7f49916b7cc7f1a2f47da6aea4ea0d45bfcdd6380d152bc

Contents?: true

Size: 1.15 KB

Versions: 15

Compression:

Stored size: 1.15 KB

Contents

require 'active_support/concern'

class QueryHelper
  module QueryHelperConcern
    extend ActiveSupport::Concern

    included do
      def query_helper
        @query_helper
      end

      def create_query_helper
        @query_helper = QueryHelper.new(**query_helper_params, api_payload: true)
      end

      def create_query_helper_filter
        filter_values = params[:filter].permit!.to_h
        QueryHelper::SqlFilter.new(filter_values: filter_values)
      end

      def create_query_helper_sort
        QueryHelper::SqlSort.new(sort_string: params[:sort])
      end

      def create_query_helper_associations
        QueryHelper::Associations.process_association_params(params[:include])
      end

      def query_helper_params
        helpers = {}
        helpers[:page] = params[:page] if params[:page]
        helpers[:per_page] = params[:per_page] if params[:per_page]
        helpers[:sql_filter] = create_query_helper_filter() if params[:filter]
        helpers[:sql_sort] = create_query_helper_sort() if params[:sort]
        helpers[:associations] = create_query_helper_associations() if params[:include]
        helpers
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
query_helper-0.2.7 lib/query_helper/query_helper_concern.rb
query_helper-0.2.6 lib/query_helper/query_helper_concern.rb
query_helper-0.2.5 lib/query_helper/query_helper_concern.rb
query_helper-0.2.4 lib/query_helper/query_helper_concern.rb
query_helper-0.2.3 lib/query_helper/query_helper_concern.rb
query_helper-0.2.2 lib/query_helper/query_helper_concern.rb
query_helper-0.2.1 lib/query_helper/query_helper_concern.rb
query_helper-0.2.0 lib/query_helper/query_helper_concern.rb
query_helper-0.1.8 lib/query_helper/query_helper_concern.rb
query_helper-0.1.6 lib/query_helper/query_helper_concern.rb
query_helper-0.1.5 lib/query_helper/query_helper_concern.rb
query_helper-0.1.3 lib/query_helper/query_helper_concern.rb
query_helper-0.1.2 lib/query_helper/query_helper_concern.rb
query_helper-0.1.1 lib/query_helper/query_helper_concern.rb
query_helper-0.1.0 lib/query_helper/query_helper_concern.rb