Sha256: 17552de27f52341f2102be916c4d725aafc26431c096c039c08276b2cebf8fe2

Contents?: true

Size: 774 Bytes

Versions: 3

Compression:

Stored size: 774 Bytes

Contents

# frozen_string_literal: true

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

      private

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
finapps-4.0.6 lib/finapps/utils/query_builder.rb
finapps-4.0.5 lib/finapps/utils/query_builder.rb
finapps-4.0.4 lib/finapps/utils/query_builder.rb