Class: CQL::MapReduce
Overview
Not a part of the public API. Subject to change at any time.
Class Method Summary collapse
-
.gather_objects(current_object, target_classes, filters) ⇒ Object
Recursively gathers all models that match the given targets and filters.
Methods included from Dsl
as, eq, from, gt, gte, lc, line, lt, lte, method_missing, name, sc, select, soc, ssoc, tags, tc, transform, with, without
Class Method Details
.gather_objects(current_object, target_classes, filters) ⇒ Object
Recursively gathers all models that match the given targets and filters
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/cql/map_reduce.rb', line 16 def self.gather_objects(current_object, target_classes, filters) gathered_objects = Array.new.tap { |gathered_objects| collect_all_in(target_classes, current_object, gathered_objects) } if filters filters.each do |filter| negate = filter[:negate] filter = filter[:filter] # Non-targeted filter, will apply to all objects if filter.is_a?(Proc) gathered_objects = filter_with_proc(gathered_objects, filter, negate) # Targeted filter, will only apply to certain objects elsif filter.is_a?(Hash) filter.keys.each do |filtered_class| clazz = determine_class(filtered_class) gathered_objects = gathered_objects.select do |object| # A class that is targeted by the filter, so proceed with determination if object.is_a?(clazz) # Block filter if filter[filtered_class].is_a?(Proc) filter[filtered_class].call(object) && !negate # Must be a predefined filter otherwise else !filter_with_predefined([object], filter[filtered_class], negate).empty? end # Not a class that is targeted by the filter, so include it else true end end end # Must be a predefined filter otherwise else gathered_objects = filter_with_predefined(gathered_objects, filter, negate) end end end gathered_objects end |