Module: Gluttonberg::Content::Publishable

Extended by:
ActiveSupport::Concern
Included in:
Gallery
Defined in:
lib/gluttonberg/content/publishable.rb

Overview

A mixin that will add simple publishing functionality to any arbitrary model. This includes finders for retrieving published records and instance methods for quickly changing the state.

Instance Method Summary collapse

Instance Method Details

#archiveObject

Change the publish state to true but not save the record.



45
46
47
# File 'lib/gluttonberg/content/publishable.rb', line 45

def archive
  self.state = "archived"
end

#archive!Object

Change the publish state to true and save the record.



50
51
52
53
# File 'lib/gluttonberg/content/publishable.rb', line 50

def archive!
  self.archive
  self.save
end

#archived?Boolean

Check to see if this record has been published.

Returns:

  • (Boolean)


61
62
63
# File 'lib/gluttonberg/content/publishable.rb', line 61

def archived?
  self.state == "archived"
end

#clean_published_dateObject



89
90
91
92
93
# File 'lib/gluttonberg/content/publishable.rb', line 89

def clean_published_date
  if self.state != "published"
    self.published_at = nil
  end  
end

#draft?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/gluttonberg/content/publishable.rb', line 65

def draft?
  self.state == "draft" || self.state == "ready" || self.state == "not_ready"
end

#publishObject

Change the publish state to draft but not save the record



34
35
36
37
# File 'lib/gluttonberg/content/publishable.rb', line 34

def publish
  self.state= "published"
  self.published_at = Time.now
end

#publish!Object

Change the publish state to true and save the record.



22
23
24
25
# File 'lib/gluttonberg/content/publishable.rb', line 22

def publish!
  self.publish
  self.save
end

#published?Boolean

Check to see if this record has been published.

Returns:

  • (Boolean)


56
57
58
# File 'lib/gluttonberg/content/publishable.rb', line 56

def published?
  self.state == "published" && published_at <= Time.zone.now
end

#publishing_statusObject



69
70
71
72
73
74
75
76
77
# File 'lib/gluttonberg/content/publishable.rb', line 69

def publishing_status
  temp_status = if draft?
    "Draft"
  else  
    self.state.capitalize unless self.state.blank?
  end
  # TODO support for 'submitted for approval'
  temp_status.html_safe 
end

#set_statusObject



79
80
81
82
83
84
85
86
87
# File 'lib/gluttonberg/content/publishable.rb', line 79

def set_status
  if ["draft", "ready", "not_ready"].include?(self.state) || self.state.blank?
    self.state = "draft"
  elsif ["published", "archived"].include?(self.state) 
    self.state = self.state
  else
    #self.state = "draft"
  end
end

#unpublishObject

Change the publish state to draft but not save the record



40
41
42
# File 'lib/gluttonberg/content/publishable.rb', line 40

def unpublish
  self.state= "draft"
end

#unpublish!Object

Change the publish state to false and save the record.



28
29
30
31
# File 'lib/gluttonberg/content/publishable.rb', line 28

def unpublish!
  self.unpublish
  self.save
end