Module: CouchPublish

Defined in:
lib/couch_publish/couch_publish.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
# File 'lib/couch_publish/couch_publish.rb', line 2

def self.included(base)
  base.send :include, Memories unless base.ancestors.include? Memories
end

Instance Method Details

#discard_draftObject

Discard the working draft, and revert the document back to the last published state, but don’t save. Note that if you save the document after calling this method, you would still have to call the publish! method if you want the revert to be published



44
45
46
47
48
# File 'lib/couch_publish/couch_publish.rb', line 44

def discard_draft
  discard_draft_exception_check
  self.rollback_to_latest_milestone
  self
end

#discard_draft!(&block) ⇒ Object

Discard the working draft, and revert the document back to the last published version



32
33
34
35
36
37
# File 'lib/couch_publish/couch_publish.rb', line 32

def discard_draft!(&block)
  discard_draft_exception_check
  self.rollback_to_latest_milestone!
  self.publish! &block
  self
end

#draft?Boolean

Returns true if this version has not been published

Returns:

  • (Boolean)


16
17
18
# File 'lib/couch_publish/couch_publish.rb', line 16

def draft?
  not self.published?
end

#last_published_versionObject

Returns the latest version of the document that was published



21
22
23
# File 'lib/couch_publish/couch_publish.rb', line 21

def last_published_version
  self.milestones.empty? ? nil : self.milestones.last.instance
end

#previously_published?Boolean

Has any of version of this document ever been published?

Returns:

  • (Boolean)


26
27
28
# File 'lib/couch_publish/couch_publish.rb', line 26

def previously_published?
  not self.milestones.empty?
end

#publish!(&block) ⇒ Object



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

def publish!(&block)
  self.milestone! &block
end

#published?Boolean

Returns true if this version is published

Returns:

  • (Boolean)


11
12
13
# File 'lib/couch_publish/couch_publish.rb', line 11

def published?
  self.milestone? or self.milestone_commit?
end

#published_versionsObject



50
51
52
# File 'lib/couch_publish/couch_publish.rb', line 50

def published_versions
  self.milestones
end