SHARE
TWEET

Untitled

a guest Oct 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Search
  2.   def execute(user, form)
  3.     filtered(MyModel, form, user).paginate(**opts)
  4.   end
  5.  
  6.   def filtered(results, form, user)
  7.     %i[
  8.       current_user
  9.       cancelled
  10.       credit_issued
  11.       credit_requested
  12.     ]
  13.     .select { |f| form.send(f).nil? }
  14.     .each { |f| results = send("filter_by_#{f}", results) }
  15.   end
  16.  
  17.   def filter_by_current_user
  18.     # some code
  19.   end
  20.  
  21.   def filter_by_cancelled
  22.     # some code
  23.   end
  24.  
  25.   def filter_by_credit_issued
  26.     # some code
  27.   end
  28.  
  29.   def filter_by_credit_requested
  30.     # some code
  31.   end
  32. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top