Sha256: b4a871ae6257fe2af8a4a88178821cd73a0100e785e0a06f6c9ba47508007475
Contents?: true
Size: 1.34 KB
Versions: 2
Compression:
Stored size: 1.34 KB
Contents
require 'rosetta_queue/adapters/base' module RosettaQueue class Adapter class << self attr_writer :user, :password, :host, :port, :options def define yield self end def reset @user, @password, @host, @port, @options, @adapter_class = nil, nil, nil, nil, nil, nil end def type=(adapter_prefix) require "rosetta_queue/adapters/#{adapter_prefix}" @adapter_class = RosettaQueue::Gateway.const_get("#{adapter_prefix.to_s.classify}Adapter") rescue LoadError raise AdapterException, "Adapter type '#{adapter_prefix}' does not match existing adapters!" end # Yield a new (connected) adapter, run whatever is in the block, and then disconnect after the # block evaluates def open raise AdapterException, "Adapter type was never defined!" unless @adapter_class adapter = @adapter_class.new({:user => @user, :password => @password, :host => @host, :port => @port, :opts => opts}) if block_given? begin yield adapter ensure adapter.disconnect end end adapter end private def opts raise AdapterException, "Adapter options should be a hash" unless @options.nil? || @options.is_a?(Hash) @options ||= {} end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rosetta_queue-0.5.2 | lib/rosetta_queue/adapter.rb |
rosetta_queue-0.5.0 | lib/rosetta_queue/adapter.rb |