Class: Livelist::Rails::FilterCollection

Inherits:
HashWithIndifferentAccess
  • Object
show all
Defined in:
lib/livelist/rails/filter_collection.rb

Instance Method Summary collapse

Instance Method Details

#as_json(query, params, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/livelist/rails/filter_collection.rb', line 29

def as_json(query, params, options = {})
  params ||= {}
  filters.map do |filter|
    filter.prepare_options(options[filter.slug])
    filter.set_criteria_counts(query, params)
    filter.as_json(params[filter.slug])
  end
end

#create_filter(options) ⇒ Object



15
16
17
18
# File 'lib/livelist/rails/filter_collection.rb', line 15

def create_filter(options)
  options.merge!(:filter_collection => self)
  self[options[:slug]] = Filter.new(options)
end

#relation(query, params, options = {}) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/livelist/rails/filter_collection.rb', line 20

def relation(query, params, options = {})
  params ||= {}
  filters.each do |filter|
    filter.prepare_options(options[filter.slug])
    query = filter.relation(query, params[filter.slug.to_s], params.empty?)
  end
  query
end

#slugsObject



11
12
13
# File 'lib/livelist/rails/filter_collection.rb', line 11

def slugs
  keys.map(&:to_sym)
end