Sha256: 151fc11ecaddf1c5719b449f6fad030f4b6f19b93375170138af36c89bf1dc57
Contents?: true
Size: 1.18 KB
Versions: 9
Compression:
Stored size: 1.18 KB
Contents
require 'tap/support/batchable_class' module Tap module Support # Batchable encapsulates the methods used to support batching # of tasks. Classes including Batchable should call <tt>super</tt> # during initialization to initialize batch, or they should # initialize batch themselves. # # See the 'Batches' section in the Tap::Task documentation for # details on how Batchable works in practice. module Batchable def self.included(mod) mod.extend Support::BatchableClass if mod.kind_of?(Class) end # The object batch. attr_reader :batch def initialize(batch=[]) @batch = batch @batch << self end # Returns true if the batch size is greater than one # (the one being self). def batched? batch.length > 1 end # Returns the index of the self in batch. def batch_index batch.index(self) end # Initializes a new batch object and adds the object to batch. # The object will be a duplicate of self. def initialize_batch_obj obj = self.dup batch << obj obj end end end end
Version data entries
9 entries across 9 versions & 2 rubygems