class Enumark::Grouping

Constants

Group

Public Class Methods

new(enumark, key, &post) click to toggle source
# File lib/enumark/grouping.rb, line 8
def initialize(enumark, key, &post)
  @lock = Mutex.new
  @collection = nil

  @enumark = enumark
  @key = key
  @post = post
end

Public Instance Methods

each(&block) click to toggle source
# File lib/enumark/grouping.rb, line 17
def each(&block)
  unless @collection
    @lock.synchronize do
      @collection = @enumark.group_by(&@key)
      @collection = @post.call(@collection) if @post
      @collection = @collection.map{ |k, items| Group.new(k, items) }
    end
  end

  @collection.each(&block)
end