Module: CopyCouch
- Defined in:
- lib/copycouch/copycouch.rb
Class Method Summary collapse
Instance Method Summary collapse
- #last_replicated_on ⇒ Object
- #last_replicated_revision ⇒ Object
- #last_replicated_to ⇒ Object
- #replicate(target, create_target = false, &updates_after_replication) ⇒ Object
- #replicated? ⇒ Boolean
Class Method Details
.included(base) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/copycouch/copycouch.rb', line 2 def self.included(base) base.property :copycouch_log do || .property :replicated_on, Time .property :replicated_to, String .property :replicated_revision, String end end |
Instance Method Details
#last_replicated_on ⇒ Object
22 23 24 |
# File 'lib/copycouch/copycouch.rb', line 22 def last_replicated_on self.copycouch_log.last.replicated_on end |
#last_replicated_revision ⇒ Object
14 15 16 |
# File 'lib/copycouch/copycouch.rb', line 14 def last_replicated_revision self.copycouch_log.last.replicated_revision end |
#last_replicated_to ⇒ Object
18 19 20 |
# File 'lib/copycouch/copycouch.rb', line 18 def last_replicated_to self.copycouch_log.last.replicated_to end |
#replicate(target, create_target = false, &updates_after_replication) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/copycouch/copycouch.rb', line 26 def replicate(target, create_target = false, &updates_after_replication) raise StandardError, "You may not replicate new (unsaved) documents" if self.new? RestClient.post( "#{self.database.server.uri}/_replicate", { :source => self.database.name, :target => target.root, :create_target => create_target, :doc_ids => [self.id] }.to_json, :content_type => :json, :accept => :json ) self.copycouch_log << {:replicated_on => Time.now, :replicated_to => target.root.gsub(%r{http://[^:]*:[^\@]*\@}, ""), :replicated_revision => self.rev} updates_after_replication.call(self) if updates_after_replication self.save! end |
#replicated? ⇒ Boolean
10 11 12 |
# File 'lib/copycouch/copycouch.rb', line 10 def replicated? !self.copycouch_log.empty? end |