class ActiveTree::ModelQuery
Attributes
initial_scope[RW]
Public Class Methods
new(initial_scope = ::ActiveTree::Model.all)
click to toggle source
# File lib/active_tree/queries/model_query.rb, line 4 def initialize(initial_scope = ::ActiveTree::Model.all) @initial_scope = initial_scope end
Public Instance Methods
by_search(scope, search = nil)
click to toggle source
Partial search by name
# File lib/active_tree/queries/model_query.rb, line 21 def by_search(scope, search = nil) search ? scope.where("lower(name) like ?", "%#{search.downcase}%") : scope end
call(params)
click to toggle source
# File lib/active_tree/queries/model_query.rb, line 8 def call(params) scope = simple_search(initial_scope, :id, params[:id]) [:owner_type, :owner_id, :status, :data_external_id, :data_provider, :type, :parent_entity_id, :parent_entity_type, :path_slug].each do |query| scope = simple_search(scope, query, params[query]) end scope = by_search(scope, params[:search]) scope end
simple_search(scope, attribute = nil, value = nil)
click to toggle source
Simple search by attribute and exact value
# File lib/active_tree/queries/model_query.rb, line 27 def simple_search(scope, attribute = nil, value = nil) valid?(attribute, value) ? scope.where(attribute => value) : scope end