lib/finapps/utils/query_builder.rb in finapps-5.0.34 vs lib/finapps/utils/query_builder.rb in finapps-5.0.35
- old
+ new
@@ -3,17 +3,26 @@
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])
+ 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