Sha256: 6b54a80ed906033f5eeb6fd4e47900e138656b0072f4259c639ac1e01eb03b4a

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

require_relative "./error"
module Basket
  module Batcher
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      def basket_options(args)
        @basket_options = args
      end

      def basket_options_hash
        raise Basket::Error, "You must specify the size of your basket!" if @basket_options.nil?
        raise Basket::Error, "You must specify a size greater than 0" if @basket_options[:size] <= 0
        @basket_options
      end
    end

    def batch
      @batch ||= Basket.config.queue_collection.pop_all(self.class.name)
    end

    def perform
      raise Basket::Error, "You must implement perform in your Basket class."
    end

    def on_success
    end

    def on_add
    end

    def on_failure
      raise error
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
basket-0.0.2 lib/basket/batcher.rb