Module: RiceCooker::Range::ClassMethods

Includes:
Helpers
Defined in:
lib/rice_cooker/range.rb

Instance Method Summary collapse

Methods included from Helpers

#apply_filter_to_collection, #apply_range_to_collection, #apply_search_to_collection, #apply_sort_to_collection, #check_filtering_param, #check_ranged_param, #check_searching_param, #check_sorting_param, #filterable_fields_for, #format_additional_param, #fuzzy_fields_for, #param_from_defaults, #parse_filtering_param, #parse_ranged_param, #parse_searching_param, #parse_sorting_param, #rangeable_fields_for, #reduce_fields_where, #reduce_where, #searchable_fields_for, #sortable_fields_for

Instance Method Details

#ranged(additional_ranged_params = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rice_cooker/range.rb', line 12

def ranged(additional_ranged_params = {})
  cattr_accessor :ranged_keys
  cattr_accessor :custom_ranges

  # On normalize tout ca
  additional_ranged_params = format_additional_param(additional_ranged_params, 'ranged')

  # On recupere tous les filtres autorisés
  allowed_keys = (rangeable_fields_for(resource_model) + additional_ranged_params.keys)

  # On recupere le default
  self.ranged_keys = allowed_keys
  self.custom_ranges = additional_ranged_params

  has_scope :range, type: :hash, only: [:index] do |_controller, scope, value|
    params = parse_ranged_param(value, ranged_keys)
    scope = apply_range_to_collection(scope, params, custom_ranges)
    scope
  end
end