Sha256: f524a06c7e5c396eb6d9888603743edf1104761777cf034fb23367d605143778

Contents?: true

Size: 775 Bytes

Versions: 5

Compression:

Stored size: 775 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]}" if params[:page]
        requested = "requested=#{params[:requested]}" if params[:requested]
        sort = "sort=#{ERB::Util.url_encode(params[:sort])}" if params[:sort]
        filter = "filter=#{ERB::Util.url_encode(filter_obj.to_json)}" if filter_obj && !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

5 entries across 5 versions & 1 rubygems

Version Path
finapps-3.0.2 lib/finapps/utils/query_builder.rb
finapps-3.0.1 lib/finapps/utils/query_builder.rb
finapps-2.3.7 lib/finapps/utils/query_builder.rb
finapps-2.3.6 lib/finapps/utils/query_builder.rb
finapps-2.3.5 lib/finapps/utils/query_builder.rb