class SeekParty::SeekPartyEngine
Attributes
inspected_class[RW]
seek_party_attribute[RW]
seek_party_query[RW]
Public Class Methods
new(inspected_class, params: {}, white_list: nil, black_list: nil, scopes: {})
click to toggle source
# File lib/seek_party/seek_party_engine.rb, line 7 def initialize(inspected_class, params: {}, white_list: nil, black_list: nil, scopes: {}) @seek_party_attribute = SeekPartyAttribute.new(inspected_class, white_list, black_list) @seek_party_query = SeekPartyQueryBuilder.new(params) @inspected_class = inspected_class @scopes = scopes end
Public Instance Methods
search()
click to toggle source
# File lib/seek_party/seek_party_engine.rb, line 20 def search spa_attribute = seek_party_attribute.discover_attributes final_query = seek_party_query.build_query(spa_attribute) run_search(final_query) end
Private Instance Methods
run_search(final_query)
click to toggle source
# File lib/seek_party/seek_party_engine.rb, line 28 def run_search(final_query) # If scopes were passed, iterate trough\ them. setup_scopes if @scopes # Execute final query (alongside any scopes that have been passed) @inspected_class.where(final_query) end
scope_call(key, value)
click to toggle source
# File lib/seek_party/seek_party_engine.rb, line 53 def scope_call(key, value) if value.present? @inspected_class = @inspected_class.method(key).call(*value) else @inspected_class = @inspected_class.method(key).call end end
setup_scopes()
click to toggle source
# File lib/seek_party/seek_party_engine.rb, line 36 def setup_scopes # Iterate trough the scopes that may have been # passed. PS: This is more of a luxury than anything # else, as the returned object from run_search is an # ActiveRecord_Relation object that would accept # method chaining @scopes.each do |scope| if scope.respond_to?(:keys) scope.keys.each do |key| scope_call(key, scope[key]) end else scope_call(scope, nil) end end end