Module: Brita

Extended by:
ActiveSupport::Concern
Defined in:
lib/brita/filter_validator.rb,
lib/brita.rb,
lib/brita/sort.rb,
lib/brita/filter.rb,
lib/brita/version.rb,
lib/brita/filtrator.rb,
lib/brita/parameter.rb,
lib/brita/value_parser.rb,
lib/brita/scope_handler.rb,
lib/brita/where_handler.rb,
lib/brita/type_validator.rb,
lib/brita/subset_comparator.rb

Overview

Here be dragons: there are two forms of metaprogramming in this file instance variables are being dynamically set based on the param name and we are class evaling ‘validates` to create dynamic validations based on the filters being validated.

Defined Under Namespace

Classes: Filter, FilterValidator, Filtrator, Parameter, ScopeHandler, Sort, SubsetComparator, TypeValidator, ValueParser, WhereHandler

Constant Summary collapse

VERSION =
"0.10.0".freeze

Instance Method Summary collapse

Instance Method Details

#filter_errorsObject



32
33
34
# File 'lib/brita.rb', line 32

def filter_errors
  filter_validator.errors.messages
end

#filter_paramsObject



20
21
22
# File 'lib/brita.rb', line 20

def filter_params
  params.fetch(:filters, {})
end

#filters_valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/brita.rb', line 28

def filters_valid?
  filter_validator.valid?
end

#filtrate(collection) ⇒ Object



16
17
18
# File 'lib/brita.rb', line 16

def filtrate(collection)
  Filtrator.filter(collection, params, filters)
end

#sort_paramsObject



24
25
26
# File 'lib/brita.rb', line 24

def sort_params
  params.fetch(:sort, "").split(",") if filters.any? { |filter| filter.is_a?(Sort) }
end