Module: Sift

Extended by:
ActiveSupport::Concern
Defined in:
lib/sift/filter_validator.rb,
lib/sift/sort.rb,
lib/sift/filter.rb,
lib/procore-sift.rb,
lib/sift/version.rb,
lib/sift/filtrator.rb,
lib/sift/parameter.rb,
lib/sift/value_parser.rb,
lib/sift/scope_handler.rb,
lib/sift/where_handler.rb,
lib/sift/type_validator.rb,
lib/sift/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 =
"1.2.0".freeze

Instance Method Summary collapse

Instance Method Details

#filter_errorsObject



34
35
36
# File 'lib/procore-sift.rb', line 34

def filter_errors
  filter_validator.errors.messages
end

#filter_paramsObject



22
23
24
# File 'lib/procore-sift.rb', line 22

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

#filters_valid?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/procore-sift.rb', line 30

def filters_valid?
  filter_validator.valid?
end

#filtrate(collection) ⇒ Object



18
19
20
# File 'lib/procore-sift.rb', line 18

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

#sort_paramsObject



26
27
28
# File 'lib/procore-sift.rb', line 26

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