Module: Sequel::Plugins::Sharding::ClassMethods

Defined in:
lib/sequel/plugins/sharding.rb

Instance Method Summary collapse

Instance Method Details

#create_using_server(s, values = OPTS, &block) ⇒ Object

Create a new object on the given shard s.



24
25
26
# File 'lib/sequel/plugins/sharding.rb', line 24

def create_using_server(s, values=OPTS, &block)
  new_using_server(s, values, &block).save
end

#eager_load_results(opts, eo, &block) ⇒ Object

Eager load the association with the given eager loader options.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/sequel/plugins/sharding.rb', line 29

def eager_load_results(opts, eo, &block)
  if (s = eo[:self]) && (server = s.opts[:server])
    eb = eo[:eager_block]
    set_server = proc do |ds|
      ds = eb.call(ds) if eb
      ds = ds.server?(server)
      ds
    end
    eo = Hash[eo]
    eo[:eager_block] = set_server
    eo
  end

  super
end

#new_using_server(s, values = OPTS, &block) ⇒ Object

Return a newly instantiated object that is tied to the given shard s. When the object is saved, a record will be inserted on shard s.



48
49
50
# File 'lib/sequel/plugins/sharding.rb', line 48

def new_using_server(s, values=OPTS, &block)
  new(values, &block).set_server(s)
end