Class: CouchReplica::Database
- Inherits:
-
Object
- Object
- CouchReplica::Database
- Defined in:
- lib/couch_replica/database.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#replicator_url ⇒ Object
readonly
Returns the value of attribute replicator_url.
-
#source_endpoint ⇒ Object
readonly
Returns the value of attribute source_endpoint.
-
#target_endpoint ⇒ Object
readonly
Returns the value of attribute target_endpoint.
Instance Method Summary collapse
- #doc_url ⇒ Object
-
#initialize(name, source_endpoint:, target_endpoint:, replicator_url:) ⇒ Database
constructor
A new instance of Database.
- #logger ⇒ Object
- #replicator_id ⇒ Object
- #source_url ⇒ Object
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
- #target_url ⇒ Object
Constructor Details
#initialize(name, source_endpoint:, target_endpoint:, replicator_url:) ⇒ Database
Returns a new instance of Database.
11 12 13 14 15 16 |
# File 'lib/couch_replica/database.rb', line 11 def initialize(name, source_endpoint:, target_endpoint:, replicator_url:) @name = name @source_endpoint = source_endpoint @target_endpoint = target_endpoint @replicator_url = replicator_url end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/couch_replica/database.rb', line 9 def name @name end |
#replicator_url ⇒ Object (readonly)
Returns the value of attribute replicator_url.
9 10 11 |
# File 'lib/couch_replica/database.rb', line 9 def replicator_url @replicator_url end |
#source_endpoint ⇒ Object (readonly)
Returns the value of attribute source_endpoint.
9 10 11 |
# File 'lib/couch_replica/database.rb', line 9 def source_endpoint @source_endpoint end |
#target_endpoint ⇒ Object (readonly)
Returns the value of attribute target_endpoint.
9 10 11 |
# File 'lib/couch_replica/database.rb', line 9 def target_endpoint @target_endpoint end |
Instance Method Details
#doc_url ⇒ Object
57 58 59 |
# File 'lib/couch_replica/database.rb', line 57 def doc_url "#{replicator_url}/#{replicator_id}" end |
#logger ⇒ Object
73 74 75 |
# File 'lib/couch_replica/database.rb', line 73 def logger @logger ||= Logger.new(STDOUT) end |
#replicator_id ⇒ Object
61 62 63 |
# File 'lib/couch_replica/database.rb', line 61 def replicator_id "pull-#{name}" end |
#source_url ⇒ Object
65 66 67 |
# File 'lib/couch_replica/database.rb', line 65 def source_url "#{source_endpoint}/#{name}" end |
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/couch_replica/database.rb', line 18 def start doc = status if doc logger.info "Replication already started from #{source_url} to #{target_url}" return end res = RestClient.post replicator_url, { _id: replicator_id, source: source_url, target: target_url, continuous: true, create_target: true }.to_json, content_type: :json logger.info "Started push replication from #{source_url} to #{target_url}" res end |
#status ⇒ Object
51 52 53 54 55 |
# File 'lib/couch_replica/database.rb', line 51 def status JSON.parse RestClient.get doc_url rescue RestClient::ResourceNotFound nil end |
#stop ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/couch_replica/database.rb', line 38 def stop doc = status if !doc logger.info "No replication found from #{source_url} to #{target_url}" return end res = RestClient.delete doc_url, params: {rev: doc['_rev']} logger.info "Stopped replication from #{source_url} to #{target_url}" res end |
#target_url ⇒ Object
69 70 71 |
# File 'lib/couch_replica/database.rb', line 69 def target_url "#{target_endpoint}/#{name}" end |