Module: Collate::ActiveRecordExtension
- Defined in:
- lib/collate/active_record_extension.rb
Instance Method Summary collapse
- #collate(params) ⇒ Object
- #collate_group(name, **opts, &blk) ⇒ Object
- #collate_on(field, opts = {}) ⇒ Object
Instance Method Details
#collate(params) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/collate/active_record_extension.rb', line 23 def collate params initialize_collate ar_rel = self.all self.collate_filters.each do |group_key, group| group[:filters].each do |filter| if params[filter.param_key].present? || params["#{filter.param_key}[]"].present? ar_rel = apply_filter(ar_rel, filter, params[filter.param_key] || params["#{filter.param_key}[]"]) end end end ar_rel end |
#collate_group(name, **opts, &blk) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/collate/active_record_extension.rb', line 14 def collate_group name, **opts, &blk initialize_collate opts[:label] ||= name.to_s.titleize self. = opts self.default_group = name blk.call end |
#collate_on(field, opts = {}) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/collate/active_record_extension.rb', line 6 def collate_on field, opts={} initialize_collate self.collate_filters[self.default_group] ||= {filters: []}.merge(self.) self.collate_filters[self.default_group][:filters] << Collate::Filter.new(field, opts.merge({base_model_table_name: self.table_name})) end |