Created
August 27, 2019 16:07
-
-
Save luisguzman02/e21642319f33f97c6a0740c8b08b88ce to your computer and use it in GitHub Desktop.
Revisions
-
luisguzman02 created this gist
Aug 27, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ module Filterable extend ActiveSupport::Concern included do scope :filtered, ->(values) { current = all filters.each do |key, method| if values.try(:key?, key) && current.respond_to?(method) current = current.send(method, values[key]) end end current } end module ClassMethods def add_filter(filter_key, method_name, callable = nil) scope(method_name, callable) if callable filters[filter_key] = method_name end def filters @filters ||= {} end end end