Module: Pickel

Defined in:
lib/pickel.rb,
lib/pickel/search.rb,
lib/pickel/version.rb,
lib/pickel/condition.rb,
lib/pickel/predicate.rb,
lib/pickel/view_helper.rb

Defined Under Namespace

Modules: ViewHelper Classes: Condition, FormBuilder, Predicate, Search

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.permit(params, *filters) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/pickel.rb', line 17

def permit(params, *filters)
  return {} unless params.key?(:q)

  expanded = filters.flat_map do |f|
    Predicate.find(f.to_s) ? f : Predicate.all.map { |predicate| "#{f}_#{predicate.id}".to_sym }
  end
  params[:q].permit(*expanded).to_h.reject { |_, v| v.blank? }
end

.search(klass, search_params) ⇒ Object



13
14
15
# File 'lib/pickel.rb', line 13

def search(klass, search_params)
  Search.new(klass.all, search_params)
end