From 0ed7ab9d66f0002911ad821af2bf45f32483ae32 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Fri, 3 Oct 2014 20:58:22 +0200 Subject: [PATCH] Memoize repeated Hash === conditional --- lib/ransack/helpers/form_helper.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ransack/helpers/form_helper.rb b/lib/ransack/helpers/form_helper.rb index 6b83dfa..3969bfe 100644 --- a/lib/ransack/helpers/form_helper.rb +++ b/lib/ransack/helpers/form_helper.rb @@ -86,10 +86,11 @@ module Ransack options = args.first.is_a?(Hash) ? args.shift.dup : {} default_order = options.delete :default_order + default_order_is_a_hash = Hash === default_order # If the default order is a hash of fields, duplicate it and let us access it with strings or symbols default_order = default_order.dup.with_indifferent_access if - Hash === default_order + default_order_is_a_hash search_params = params[search.context.search_key].presence || {}.with_indifferent_access @@ -115,7 +116,7 @@ module Ransack new_dir = if current_dir current_dir == desc ? asc : desc - elsif Hash === default_order + elsif default_order_is_a_hash default_order[attr_name] || asc else default_order || asc