Class: Livelist::Rails::FilterCollection
- Inherits:
-
HashWithIndifferentAccess
- Object
- HashWithIndifferentAccess
- Livelist::Rails::FilterCollection
- Defined in:
- lib/livelist/rails/filter_collection.rb
Instance Method Summary collapse
- #as_json(query, params, options = {}) ⇒ Object
- #create_filter(options) ⇒ Object
- #relation(query, params, options = {}) ⇒ Object
- #slugs ⇒ Object
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, = {}) params ||= {} filters.map do |filter| filter.([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() .merge!(:filter_collection => self) self[[:slug]] = Filter.new() 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, = {}) params ||= {} filters.each do |filter| filter.([filter.slug]) query = filter.relation(query, params[filter.slug.to_s], params.empty?) end query end |
#slugs ⇒ Object
11 12 13 |
# File 'lib/livelist/rails/filter_collection.rb', line 11 def slugs keys.map(&:to_sym) end |