Module: Cloudant::Replicator

Included in:
API
Defined in:
lib/cloudant/replicator.rb

Instance Method Summary collapse

Instance Method Details

#active_tasks(type = "replication") ⇒ Object

The Replicator Module contains methods to replicate a database

Allows you to monitor a replication



6
7
8
# File 'lib/cloudant/replicator.rb', line 6

def active_tasks(type="replication")
  @conn.query({url_path: "_active_tasks", opts: {"type" => type}, method: :get})
end

#build_doc(opts) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cloudant/replicator.rb', line 23

def build_doc(opts)
  fields = [:continuous,:create_target,:doc_ids,:filter,:proxy,:selector,:since_seq,:use_checkpoints,:user_ctx]

  replication_doc = {
    :source => "https://#{username}:#{password}@#{username}.cloudant.com/#{database}",
    :target => "https://#{username}:#{password}@#{username}.cloudant.com/#{opts[:target]}",
    :create_target => true,
    :continuous => false
  }  

  fields.each do |field|
    current = field.to_sym
    replication_doc[current] = opts[current] if !opts[current].nil?
  end    

  replication_doc
end

#replicate_db(target, *opts) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/cloudant/replicator.rb', line 10

def replicate_db(target,*opts)
  opts && opts[0] ? options = opts[0] : options = {}

  options[:target] = target
  replication_doc  = build_doc(options)
  doc_name = Cloudant::Utility.generate_doc_name(database,target)
  @conn.query({url_path: "_replicator/#{doc_name}", opts: replication_doc, method: :put})
end

#sync(target) ⇒ Object



19
20
21
# File 'lib/cloudant/replicator.rb', line 19

def sync(target)
  replicate_db(target,{:continuous => true, :create_target => true})
end