Module: Card::Set::Abstract::FilterHelper

Extended by:
Card::Set
Defined in:
tmpsets/set/mod020-search/abstract/00_filter_helper.rb

Overview

TODO: move sort/filter handling out of card and into base format

Defined Under Namespace

Modules: Format

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



8
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 8

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/search/set/abstract/00_filter_helper.rb"; end

Instance Method Details

#default_filter_optionObject



45
46
47
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 45

def default_filter_option
  {}
end

#filter_hashObject

FIXME: it is inconsistent that #sort_hash has :sort as the key, but

filter_hash is the value of the hash with :filter as the key.



21
22
23
24
25
26
27
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 21

def filter_hash
  @filter_hash ||= begin
    filter = Env.params[:filter]
    filter = filter.to_unsafe_h if filter&.respond_to?(:to_unsafe_h)
    filter.is_a?(Hash) ? filter : {}
  end
end

#filter_keys_with_valuesObject



38
39
40
41
42
43
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 38

def filter_keys_with_values
  filter_keys.map do |key|
    values = filter_param(key)
    values.present? ? [key, values] : next
  end.compact
end

#filter_param(field) ⇒ Object



15
16
17
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 15

def filter_param field
  filter_hash[field.to_sym]
end

#offsetObject



49
50
51
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 49

def offset
  param_to_i :offset, 0
end

#safe_sql_param(key) ⇒ Object



33
34
35
36
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 33

def safe_sql_param key
  param = Env.params[key]
  param.blank? ? nil : Card::Query.safe_sql(param)
end

#sort_hashObject

sorting and filtering is about viewing the data, not altering the data itself.



11
12
13
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 11

def sort_hash
  sort_param.present? ? { sort: sort_param } : {}
end

#sort_paramObject



29
30
31
# File 'tmpsets/set/mod020-search/abstract/00_filter_helper.rb', line 29

def sort_param
  safe_sql_param :sort
end