Sha256: 97524f3005400bf734eb847c93ef6136f50c30bcc884a1c6fb00b444348d599d

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 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 MissingSourceFile
          raise AdapterException, "Adapter type '#{adapter_prefix}' does not match existing adapters!"
      end

      def instance
        raise AdapterException, "Adapter type was never defined!" unless @adapter_class
        @adapter_class.new({:user => @user, :password => @password, :host => @host, :port => @port, :opts => opts})
      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

4 entries across 4 versions & 1 rubygems

Version Path
cwyckoff-rosetta_queue-0.1.4 lib/rosetta_queue/adapter.rb
cwyckoff-rosetta_queue-0.2.1 lib/rosetta_queue/adapter.rb
cwyckoff-rosetta_queue-0.2.2 lib/rosetta_queue/adapter.rb
cwyckoff-rosetta_queue-0.3.0 lib/rosetta_queue/adapter.rb