Sha256: d6c6e8cdd53b69733fa9ebd11faa4d18b4c4a90ac28501a621ddb6c084f7abad

Contents?: true

Size: 991 Bytes

Versions: 40

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

module FinApps
  module Utils
    module QueryBuilder
      def build_query_path(root_url, params)
        filter_obj = build_filter(params)
        filter = "filter=#{ERB::Util.url_encode(filter_obj.to_json)}" unless filter_obj.empty?
        query_join(root_url, [page(params), requested(params), sort(params), filter])
      end

      private

      def page(params)
        "page=#{params[:page].to_i}" if params[:page]
      end

      def requested(params)
        "requested=#{params[:requested].to_i}" if params[:requested]
      end

      def sort(params)
        "sort=#{ERB::Util.url_encode(params[:sort])}" if params[:sort]
      end

      def query_join(root_url, params_array)
        query_string = params_array.compact.join('&')
        [root_url, query_string].reject(&:empty?).join('?')
      end

      def build_filter(_params)
        # stub, to be overwritten by classes that include this module
        {}
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
finapps-6.13.1 lib/finapps/utils/query_builder.rb
finapps-6.13.0 lib/finapps/utils/query_builder.rb
finapps-6.12.0 lib/finapps/utils/query_builder.rb
finapps-6.11.0 lib/finapps/utils/query_builder.rb
finapps-6.10.2 lib/finapps/utils/query_builder.rb
finapps-6.10.1 lib/finapps/utils/query_builder.rb
finapps-6.10.0 lib/finapps/utils/query_builder.rb
finapps-6.9.2 lib/finapps/utils/query_builder.rb
finapps-6.9.1 lib/finapps/utils/query_builder.rb
finapps-6.9.0 lib/finapps/utils/query_builder.rb
finapps-6.8.0 lib/finapps/utils/query_builder.rb
finapps-6.7.1 lib/finapps/utils/query_builder.rb
finapps-6.7.0 lib/finapps/utils/query_builder.rb
finapps-6.6.1 lib/finapps/utils/query_builder.rb
finapps-6.6.0 lib/finapps/utils/query_builder.rb
finapps-6.5.0 lib/finapps/utils/query_builder.rb
finapps-6.4.3 lib/finapps/utils/query_builder.rb
finapps-6.4.2 lib/finapps/utils/query_builder.rb
finapps-6.4.1 lib/finapps/utils/query_builder.rb
finapps-6.4.0 lib/finapps/utils/query_builder.rb