Class: Post2

Inherits:
Object
  • Object
show all
Includes:
LuckySneaks::StringExtensions, Mongoid::Document, Mongoid::Timestamps, Tanker
Defined in:
app/models/post2.rb

Constant Summary collapse

STATES =

Constants ======================================================================================

['draft', 'published']

Instance Method Summary collapse

Instance Method Details

#draft?Boolean

Instance methods ===============================================================================

Returns:

  • (Boolean)


63
64
65
# File 'app/models/post2.rb', line 63

def draft?
  self.state == 'draft' || self.state.nil?
end

#full_pathObject



67
68
69
# File 'app/models/post2.rb', line 67

def full_path
  self.path
end

#humanize_pathObject



71
72
73
# File 'app/models/post2.rb', line 71

def humanize_path
  "/#{self.slug}".gsub('//', '/')
end

#my_indexObject



75
76
77
# File 'app/models/post2.rb', line 75

def my_index
  self.blog.posts.index(self)
end

#next_postObject



79
80
81
82
83
# File 'app/models/post2.rb', line 79

def next_post
  i = self.my_index + 1
  i = 0 if i > (self.blog.posts.size - 1)
  self.blog.posts[i]
end

#pathObject



85
86
87
# File 'app/models/post2.rb', line 85

def path
  "#{self.blog.humanize_path}#{self.humanize_path}".gsub('//', '/')
end

#previous_postObject



89
90
91
92
93
# File 'app/models/post2.rb', line 89

def previous_post
  i = self.my_index - 1
  i = self.blog.posts.size - 1 if i < 0
  self.blog.posts[i]
end

#publish!Object



95
96
97
# File 'app/models/post2.rb', line 95

def publish!
  self.update_attributes :state => 'published', :published_at => Time.zone.now
end

#published?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'app/models/post2.rb', line 99

def published?
  self.state == 'published'
end

#search_descriptionObject



103
104
105
# File 'app/models/post2.rb', line 103

def search_description
  self.summary.gsub(/<\/?[^>]*>/, '')[0..199].html_safe
end

#search_titleObject



107
108
109
# File 'app/models/post2.rb', line 107

def search_title
  self.title
end

#set_slugObject

Sets the slug for this locale. Slugs from the locale tree are used to build this locale’s URL.



112
113
114
# File 'app/models/post2.rb', line 112

def set_slug
  self.slug = self.title.to_s.to_url
end

#state=(arg) ⇒ Object



120
121
122
# File 'app/models/post2.rb', line 120

def state=(arg)
  self[:state] = arg.downcase
end

#statusObject



124
125
126
# File 'app/models/post2.rb', line 124

def status
  self.state ? self.state.capitalize : 'Draft'
end

#unpublish!Object



116
117
118
# File 'app/models/post2.rb', line 116

def unpublish!
  self.update_attributes :state => 'draft'
end