module Cuprum::Collections::Commands::AbstractFindMatching
Abstract implementation of the FindMatching command.
Subclasses must define the build_query method, which returns an empty Query
instance for that collection.
Private Instance Methods
apply_query(criteria:, limit:, offset:, order:, scope:)
click to toggle source
# File lib/cuprum/collections/commands/abstract_find_matching.rb, line 14 def apply_query(criteria:, limit:, offset:, order:, scope:) query = scope || build_query query = query.limit(limit) if limit query = query.offset(offset) if offset query = query.order(order) if order query = query.where(criteria, strategy: :unsafe) unless criteria.empty? success(query) end
parse_criteria(strategy:, where:, &block)
click to toggle source
# File lib/cuprum/collections/commands/abstract_find_matching.rb, line 24 def parse_criteria(strategy:, where:, &block) return [] if strategy.nil? && where.nil? && !block_given? Cuprum::Collections::Queries::Parse.new.call( strategy: strategy, where: where || block ) end
process( envelope: false, limit: nil, offset: nil, order: nil, scope: nil, strategy: nil, where: nil, &block )
click to toggle source
# File lib/cuprum/collections/commands/abstract_find_matching.rb, line 33 def process( # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists envelope: false, limit: nil, offset: nil, order: nil, scope: nil, strategy: nil, where: nil, &block ) criteria = step do parse_criteria(strategy: strategy, where: where, &block) end query = step do apply_query( criteria: criteria, limit: limit, offset: offset, order: order, scope: scope ) end envelope ? wrap_query(query) : query.each end
wrap_query(query)
click to toggle source
# File lib/cuprum/collections/commands/abstract_find_matching.rb, line 60 def wrap_query(query) { collection_name => query.to_a } end