Class: DataMapper::Adapters::MasterSlaveAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- DataMapper::Adapters::MasterSlaveAdapter
show all
- Extended by:
- Forwardable
- Defined in:
- lib/data_mapper/adapters/master_slave_adapter.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of MasterSlaveAdapter.
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 15
def initialize(name, options)
super
@slave = if @options[:slave].kind_of?(AbstractAdapter)
@options[:slave]
else
assert_kind_of 'options', @options[:slave], Hash
Adapters.new(name, @options[:slave])
end
@master = if @options[:master].kind_of?(AbstractAdapter)
@options[:master]
else
assert_kind_of 'options', @options[:master], Hash
Adapters.new(name, @options[:master])
end
@reader = @slave
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
77
78
79
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 77
def method_missing(meth, *args, &block)
writer.send(meth, *args, &block)
end
|
Instance Attribute Details
#master ⇒ Object
Returns the value of attribute master.
10
11
12
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 10
def master
@master
end
|
#slave ⇒ Object
Returns the value of attribute slave.
9
10
11
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 9
def slave
@slave
end
|
Instance Method Details
#bind_to_master ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 35
def bind_to_master
original_reader, @reader = @reader, @master
if block_given?
begin
yield
ensure
@reader = original_reader
end
else
self
end
end
|
#bound_to_master? ⇒ Boolean
49
50
51
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 49
def bound_to_master?
@reader.equal?(@master)
end
|
#kind_of?(kind) ⇒ Boolean
58
59
60
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 58
def kind_of?(kind)
super || master.kind_of?(kind)
end
|
#reset_binding ⇒ Object
53
54
55
56
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 53
def reset_binding
@reader = @slave
self
end
|
#respond_to?(method) ⇒ Boolean
62
63
64
|
# File 'lib/data_mapper/adapters/master_slave_adapter.rb', line 62
def respond_to?(method)
super || master.respond_to?(method)
end
|