Sha256: aa7ee29778a8c4891c140aad64b473a6a6aad0413767d406e8dd60015bc12046
Contents?: true
Size: 1.11 KB
Versions: 4
Compression:
Stored size: 1.11 KB
Contents
module ROM module RA class Operation class Group # FIXME: only reading from a relation should be allowed here so this is # obviously too much include Charlatan.new(:relation) include Enumerable attr_reader :options, :header def initialize(relation, options) super @options = options @header = relation.header + options.keys - attribute_names end def each(&block) return to_enum unless block tuples = relation.to_a result = tuples.each_with_object({}) do |tuple, grouped| left = tuple.reject { |k,_| attribute_names.include?(k) } right = tuple.reject { |k,_| !attribute_names.include?(k) } grouped[left] ||= {} grouped[left][key] ||= [] grouped[left][key] << right if right.values.any? end result.map { |k,v| k.merge(v) }.each(&block) end def key options.keys.first end def attribute_names options.values.first end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rom-0.4.1 | lib/rom/ra/operation/group.rb |
rom-0.4.0 | lib/rom/ra/operation/group.rb |
rom-0.3.1 | lib/rom/ra/operation/group.rb |
rom-0.3.0 | lib/rom/ra/operation/group.rb |