Module: Wallaby::FilterUtils

Defined in:
lib/utils/wallaby/filter_utils.rb

Overview

Filter utils

Class Method Summary collapse

Class Method Details

.filter_name_by(filter_name, filters) ⇒ String, Symbol

Find filter name in the following precedences from high to low:

  • ‘filter_name` argument

  • filters that has been marked as default

  • ‘:all`

Parameters:

  • filter_name (String, Symbol)

    filter name

  • filters (Hash)

    filter metadata

Returns:

  • (String, Symbol)


14
15
16
17
18
# File 'lib/utils/wallaby/filter_utils.rb', line 14

def self.filter_name_by(filter_name, filters)
  filter = filter_name # from param
  filter ||= filters.find { |_k, v| v[:default] }.try(:first) # from default value
  filter || :all # last resort
end