Class: RosettaQueue::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/rosetta_queue/adapter.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.host=(value) ⇒ Object (writeonly)

Sets the attribute host

Parameters:

  • value

    the value to set the attribute host to.



7
8
9
# File 'lib/rosetta_queue/adapter.rb', line 7

def host=(value)
  @host = value
end

.options=(value) ⇒ Object (writeonly)

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



7
8
9
# File 'lib/rosetta_queue/adapter.rb', line 7

def options=(value)
  @options = value
end

.password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



7
8
9
# File 'lib/rosetta_queue/adapter.rb', line 7

def password=(value)
  @password = value
end

.port=(value) ⇒ Object (writeonly)

Sets the attribute port

Parameters:

  • value

    the value to set the attribute port to.



7
8
9
# File 'lib/rosetta_queue/adapter.rb', line 7

def port=(value)
  @port = value
end

.user=(value) ⇒ Object (writeonly)

Sets the attribute user

Parameters:

  • value

    the value to set the attribute user to.



7
8
9
# File 'lib/rosetta_queue/adapter.rb', line 7

def user=(value)
  @user = value
end

Class Method Details

.define {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



9
10
11
# File 'lib/rosetta_queue/adapter.rb', line 9

def define
  yield self
end

.openObject

Yield a new (connected) adapter, run whatever is in the block, and then disconnect after the block evaluates

Raises:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rosetta_queue/adapter.rb', line 27

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

.resetObject



13
14
15
# File 'lib/rosetta_queue/adapter.rb', line 13

def reset
  @user, @password, @host, @port, @options, @adapter_class = nil, nil, nil, nil, nil, nil
end

.type=(adapter_prefix) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/rosetta_queue/adapter.rb', line 17

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