class CacheJSON::Worker::AllPermutations
Public Instance Methods
all_argument_permutations(klass)
click to toggle source
# File lib/cache_json/worker.rb, line 62 def all_argument_permutations(klass) refresh_options = klass.cache_json_full_options[:refresh] if refresh_options all_combinations_with_fixed_points({}, refresh_options[:arguments]) else [] end end
all_cache_classes()
click to toggle source
# File lib/cache_json/worker.rb, line 55 def all_cache_classes # TODO: make this more efficient ObjectSpace.each_object(Class).select do |klass| klass.included_modules.include? CacheJSON::Base end end
all_combinations_with_fixed_points(fixed_points, full_hash)
click to toggle source
# File lib/cache_json/worker.rb, line 71 def all_combinations_with_fixed_points(fixed_points, full_hash) non_fixed_points = full_hash.dup.delete_if { |k, _| fixed_points.key?(k) } if non_fixed_points.empty? [fixed_points] else pivot_key = non_fixed_points.keys.first values_for_key(non_fixed_points, pivot_key).flat_map do |pivot_key_value| new_fixed_points = fixed_points.merge(Hash[pivot_key, pivot_key_value]) all_combinations_with_fixed_points(new_fixed_points, full_hash) end end end
results()
click to toggle source
# File lib/cache_json/worker.rb, line 44 def results all_cache_classes.flat_map do |klass| all_argument_permutations(klass).map do |args| { klass: klass, args: args } end end end
values_for_key(hsh, key)
click to toggle source
# File lib/cache_json/worker.rb, line 84 def values_for_key(hsh, key) pivot_key_values = hsh[key] if pivot_key_values.is_a?(Proc) pivot_key_values.call elsif pivot_key_values.is_a?(Range) || pivot_key_values.is_a?(Array) pivot_key_values else [pivot_key_values] end end