Sha256: 161a180016a9c9f9904ec584e0ad3e0bc08ae9736003be95b70bb9ea0fc3b3b1
Contents?: true
Size: 829 Bytes
Versions: 2
Compression:
Stored size: 829 Bytes
Contents
module Filternator class Filter attr_reader :scope, :scope_name, :presenter, :all_filters, :default_filter def initialize(options = {}) @scope = options.fetch(:scope) @scope_name = options.fetch(:scope_name) { derive_scope_name } @presenter = options.fetch(:presenter) { null_presenter } @all_filters = options.fetch(:all_filters) { scope.all_filters } @default_filter = options.fetch(:default_filter) { "all" } end def stats Hash[ all_filters.map { |filter| [ filter, apply(filter: filter).count ] } ] end def apply(params) ApplyFilter.new(self, params) end private def derive_scope_name scope.model_name.element.pluralize end def null_presenter lambda { |item| item } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
filternator-0.0.2 | lib/filternator/filter.rb |
filternator-0.0.1 | lib/filternator/filter.rb |