Module: Models::SearchableView::ClassMethods
- Defined in:
- app/concerns/models/searchable_view.rb
Overview
ActiveSupport::Concern mixin: class methods.
Instance Method Summary collapse
-
#append_rep_condition(rep_key, reps) ⇒ Object
A helper method for classic rep conditions.
- #main_resource_class ⇒ Object
- #main_resource_table ⇒ Object
-
#ransackable_scopes(_auth_object = nil) ⇒ Object
Expose rep includes scopes to Ransack so they are callable via ransack(query_params).
- #select_sort_columns ⇒ Object
Instance Method Details
#append_rep_condition(rep_key, reps) ⇒ Object
A helper method for classic rep conditions
38 39 40 41 42 43 44 |
# File 'app/concerns/models/searchable_view.rb', line 38 def append_rep_condition(rep_key, reps) rep_ids = [reps.dup].flatten.compact.uniq rep_conditions = [] rep_conditions << "#{rep_key} IS NULL" if rep_ids.delete('Unassigned') rep_conditions << "#{rep_key} IN (#{rep_ids.map(&:to_i).join(',')})" if rep_ids.present? where(rep_conditions.map { |c| "(#{c})" }.join(' OR ')) end |
#main_resource_class ⇒ Object
46 47 48 |
# File 'app/concerns/models/searchable_view.rb', line 46 def main_resource_class name.match(/View(.+)/)[1] end |
#main_resource_table ⇒ Object
50 51 52 |
# File 'app/concerns/models/searchable_view.rb', line 50 def main_resource_table main_resource_class.tableize end |
#ransackable_scopes(_auth_object = nil) ⇒ Object
Expose rep includes scopes to Ransack so they are callable via ransack(query_params).
Each scope is generated conditionally based on which rep columns the view has.
60 61 62 63 64 65 |
# File 'app/concerns/models/searchable_view.rb', line 60 def ransackable_scopes(_auth_object = nil) %i[primary_sales_rep_id_includes secondary_sales_rep_id_includes local_sales_rep_id_includes service_rep_id_includes technical_support_rep_id_includes opportunity_local_sales_rep_id_includes customer_local_sales_rep_id_includes] end |
#select_sort_columns ⇒ Object
54 55 56 |
# File 'app/concerns/models/searchable_view.rb', line 54 def select_sort_columns column_names.sort.map { |cn| [human_attribute_name(cn), cn] } end |