Class: DataMapper::Adapters::ReaderPoolAdapter

Inherits:
AbstractAdapter
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/data_mapper/adapters/reader_pool_adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ ReaderPoolAdapter

Returns a new instance of ReaderPoolAdapter.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/data_mapper/adapters/reader_pool_adapter.rb', line 13

def initialize(name, options)
  super

  assert_kind_of 'options', @options[:pool], Array

  raise ArgumentError, "The are no adapters in the adapter pool" if @options[:pool].empty?

  @pool = []
  @options[:pool].each do |adapter_options|
    adapter = if adapter_options.kind_of?(AbstractAdapter)
      adapter_options
    else
      assert_kind_of 'pool_adapter_options', adapter_options, Hash
      Adapters.new(name, adapter_options)
    end

    @pool.push(adapter)
  end

  @number_generator = Random.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



35
36
37
# File 'lib/data_mapper/adapters/reader_pool_adapter.rb', line 35

def method_missing(meth, *args, &block)
  random_adapter.send(meth, *args, &block)
end

Instance Attribute Details

#poolObject (readonly)

Returns the value of attribute pool.



9
10
11
# File 'lib/data_mapper/adapters/reader_pool_adapter.rb', line 9

def pool
  @pool
end

Instance Method Details

#kind_of?(kind) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/data_mapper/adapters/reader_pool_adapter.rb', line 39

def kind_of?(kind)
  super || random_adapter.kind_of?(kind)
end