Module: MyStuff::MultiDB::Sharded

Defined in:
lib/my_stuff/multidb/sharded.rb

Class Method Summary collapse

Class Method Details

.included(othermod) ⇒ Object

:nodoc:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/my_stuff/multidb/sharded.rb', line 8

def self.included othermod # :nodoc:
  othermod.send :include, MyStuff::MultiDB

  class <<othermod
    def with_master_for id, &block
      MyStuff::MultiDB.with_spec(
        self,
        self.spec_for_master(id),
        &block
      )
    end

    def with_master_for_new &block
      MyStuff::MultiDB.with_spec(
        self,
        self.spec_for_new,
        &block
      )
    end

    def with_slave_for id, &block
      MyStuff::MultiDB.with_spec(
        self,
        self.spec_for_slave(id),
        &block
      )
    end

    def spec_for_new; raise NotImplementedError.new; end
    def spec_for_master(shard_id); raise NotImplementedError.new; end
    def spec_for_slave(shard_id); raise NotImplementedError.new; end
  end
end