module Access class Aggregations def self.process_batch(chunk) chunk.map { |aggs| new(aggs) } end def initialize(values) self.class.class_eval {attr_reader *values.keys } values.each do |attribute_name, attribute_value| self.instance_variable_set("@#{attribute_name}", attribute_value) end @subcategories = Access::Category.process_batch(@subcategories) if @subcategories @facets = Access::Aggregations.process_batch(@facets) if @facets end end end