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) ⇒ ActiveRecord::Relation
A helper method for classic rep conditions.
-
#main_resource_class ⇒ String
Name of the underlying resource class, derived from the view name.
-
#main_resource_table ⇒ String
Tableized name of the underlying resource class.
-
#ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>
Expose rep includes scopes to Ransack so they are callable via ransack(query_params).
-
#select_sort_columns ⇒ Array<Array(String, String)>
Humanized column labels paired with column names, for sort pickers.
Instance Method Details
#append_rep_condition(rep_key, reps) ⇒ ActiveRecord::Relation
A helper method for classic rep conditions
Builds a WHERE clause matching rows whose rep_key column is one
of the given reps, treating the pseudo-rep 'Unassigned' as
rep_key IS NULL.
66 67 68 69 70 71 72 |
# File 'app/concerns/models/searchable_view.rb', line 66 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 ⇒ String
Name of the underlying resource class, derived from the view name.
77 78 79 |
# File 'app/concerns/models/searchable_view.rb', line 77 def main_resource_class name.match(/View(.+)/)[1] end |
#main_resource_table ⇒ String
Tableized name of the underlying resource class.
84 85 86 |
# File 'app/concerns/models/searchable_view.rb', line 84 def main_resource_table main_resource_class.tableize end |
#ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>
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.
100 101 102 103 104 105 |
# File 'app/concerns/models/searchable_view.rb', line 100 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 ⇒ Array<Array(String, String)>
Humanized column labels paired with column names, for sort pickers.
91 92 93 |
# File 'app/concerns/models/searchable_view.rb', line 91 def select_sort_columns column_names.sort.map { |cn| [human_attribute_name(cn), cn] } end |