Class: ActiveRecord::SearchService
- Inherits:
-
Object
- Object
- ActiveRecord::SearchService
- Defined in:
- app/services/active_record/search_service.rb
Defined Under Namespace
Classes: Filter, Order, Paginate, Search
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#paginate ⇒ Object
readonly
Returns the value of attribute paginate.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#search ⇒ Object
readonly
Returns the value of attribute search.
Instance Method Summary collapse
-
#initialize(model, original_params, options = {}) ⇒ SearchService
constructor
A new instance of SearchService.
- #run ⇒ Object
Constructor Details
#initialize(model, original_params, options = {}) ⇒ SearchService
Returns a new instance of SearchService.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/services/active_record/search_service.rb', line 97 def initialize(model, original_params, = {}) @model = model @params = original_params.deep_dup.with_indifferent_access @options = _order_str = .delete(:order_str) || params.delete(:order_str) _order = .delete(:order) || params.delete(:order) || 'id' _direction = .delete(:direction) || params.delete(:direction) || 'desc' _per_page = .delete(:per_page) || params.delete(:per_page) @search = Search.new(params, .delete(:search) || {}) @filters = Filter.new(params.delete(:filters) || {}) @order = Order.new(_order, _direction, _order_str) @paginate = Paginate.new(params.delete(:page), _per_page) end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
95 96 97 |
# File 'app/services/active_record/search_service.rb', line 95 def filters @filters end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
95 96 97 |
# File 'app/services/active_record/search_service.rb', line 95 def model @model end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
95 96 97 |
# File 'app/services/active_record/search_service.rb', line 95 def @options end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
95 96 97 |
# File 'app/services/active_record/search_service.rb', line 95 def order @order end |
#paginate ⇒ Object (readonly)
Returns the value of attribute paginate.
95 96 97 |
# File 'app/services/active_record/search_service.rb', line 95 def paginate @paginate end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
95 96 97 |
# File 'app/services/active_record/search_service.rb', line 95 def params @params end |
#search ⇒ Object (readonly)
Returns the value of attribute search.
95 96 97 |
# File 'app/services/active_record/search_service.rb', line 95 def search @search end |
Instance Method Details
#run ⇒ Object
113 114 115 116 117 118 119 |
# File 'app/services/active_record/search_service.rb', line 113 def run resources = model.where(params.slice(*model.column_names.collect(&:to_sym))).where() [search, filters, order, paginate].each do |operation| resources = operation.apply(resources) end resources end |