Sha256: 946ae8681eccb42c61fecc20f9cc054649c304bfbd4bc1007c2bc67e1b63583d

Contents?: true

Size: 605 Bytes

Versions: 14

Compression:

Stored size: 605 Bytes

Contents

module Headmin
  module Filterable
    # Will create a Headmin::Filters object with a default configuration for "id" and "search"
    #
    # Example:
    #
    # orders = Order
    # orders = filter(orders, {
    #  status: :text,
    #  price: :number,
    #  in_stock: :boolean
    #  })
    # @orders = orders.all

    def filter(collection, filter_types = {})
      type_hash = default_filter_types.merge(filter_types)
      Headmin::Filters.new(params, type_hash).query(collection)
    end

    def default_filter_types
      {
        id: :number,
        search: :search
      }
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
headmin-0.6.3 app/controllers/concerns/headmin/filterable.rb
headmin-0.6.2 app/controllers/concerns/headmin/filterable.rb
headmin-0.6.1 app/controllers/concerns/headmin/filterable.rb
headmin-0.6.0 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.9 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.8 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.7 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.6 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.5 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.4 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.3 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.2 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.1 app/controllers/concerns/headmin/filterable.rb
headmin-0.5.0 app/controllers/concerns/headmin/filterable.rb