Module: Searching

Defined in:
lib/mumuki/classroom/models/searching.rb,
lib/mumuki/classroom/models/searching/guide_progress.rb

Defined Under Namespace

Modules: GuideProgress, QueryOperands Classes: BaseFilter, NumericFilter, StudentFilter

Constant Summary collapse

VALID_PARAMS =
[:query_param, :query_operand]

Class Method Summary collapse

Class Method Details

.default_filterObject



30
31
32
# File 'lib/mumuki/classroom/models/searching.rb', line 30

def self.default_filter
  StudentFilter
end

.filter_class_for(criteria, collection) ⇒ Object



43
44
45
46
47
# File 'lib/mumuki/classroom/models/searching.rb', line 43

def self.filter_class_for(criteria, collection)
  if criteria.present?
    "#{self}::#{collection.model_name}::#{criteria.camelize}".safe_constantize
  end
end

.filter_for(collection, query_params) ⇒ Object



34
35
36
37
# File 'lib/mumuki/classroom/models/searching.rb', line 34

def self.filter_for(collection, query_params)
  filter_class = filter_class_for(query_params[:query_criteria], collection) || default_filter
  filter_class.new(valid_params(query_params))
end

.valid_params(params) ⇒ Object



39
40
41
# File 'lib/mumuki/classroom/models/searching.rb', line 39

def self.valid_params(params)
  params.select { |it| VALID_PARAMS.include? it }
end