Sha256: 0a736838f3a948c5b7a0e579424e826fa572c1ebce8ed73b303a7d27ee07f1b8
Contents?: true
Size: 1.54 KB
Versions: 4
Compression:
Stored size: 1.54 KB
Contents
module Basket class HandleAdd def self.call(queue, data) new(queue, data).call end def initialize(queue, data) @queue = queue @data = data end def call setup_batchers add_to_basket perform if basket_full?(@queue_length, @queue_class) rescue => error maybe_raise_basket_error(error) failure(error) end private def setup_batchers @queue_collection = Basket.queue_collection @queue_class = class_for_queue @queue_instance = @queue_class.new end def add_to_basket(data = @data) @queue_length = @queue_collection.push(@queue, data) @queue_instance.define_singleton_method(:element) { data } @queue_instance.on_add end def perform @queue_instance.perform @queue_instance.on_success @queue_collection.clear(@queue) end def failure(error) @queue_instance.define_singleton_method(:error) { error } @queue_instance.on_failure end def class_for_queue raise_basket_not_found unless Object.const_defined?(@queue) Object.const_get(@queue) end def raise_basket_not_found raise Basket::BasketNotFoundError, "We couldn't find that basket anywhere, please make sure it is defined." end def basket_full?(queue_length, queue_class) queue_length == queue_class.basket_options_hash[:size] end def maybe_raise_basket_error(e) raise e if e.instance_of?(Basket::Error) raise e if e.instance_of?(Basket::BasketNotFoundError) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
basket-0.0.7 | lib/basket/handle_add.rb |
basket-0.0.6 | lib/basket/handle_add.rb |
basket-0.0.5 | lib/basket/handle_add.rb |
basket-0.0.4 | lib/basket/handle_add.rb |