Class: Blogaze::Models::Post

Inherits:
Sequel::Model
  • Object
show all
Defined in:
lib/blogaze/models/post.rb

Overview

Post model

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#post_tagsObject

Returns the value of attribute post_tags.



15
16
17
# File 'lib/blogaze/models/post.rb', line 15

def 
  @post_tags
end

Instance Method Details

#after_saveObject



78
79
80
# File 'lib/blogaze/models/post.rb', line 78

def after_save
  process_tags
end

#before_createObject



65
66
67
68
69
70
71
# File 'lib/blogaze/models/post.rb', line 65

def before_create
  super
  self.slug = Innate::Helper::CGI.u(self.title.scan(/\w+/).join('-')).downcase
  self.created_at = Time.now.to_i
  self.published_at = Time.now.to_i
  self.updated_at = 0
end

#before_saveObject



73
74
75
76
# File 'lib/blogaze/models/post.rb', line 73

def before_save
  self.slug = Innate::Helper::CGI.u(self.title.scan(/\w+/).join('-')).downcase
  self.updated_at = Time.now.to_i
end

#body_partialString

Returns the partial body of the post.

Returns:

  • (String)


52
53
54
55
# File 'lib/blogaze/models/post.rb', line 52

def body_partial
  body = self.body.split('<!-- MORE -->')
  return body[0]
end

#hrefString

Returns the URI to the post.

Returns:

  • (String)


28
29
30
# File 'lib/blogaze/models/post.rb', line 28

def href
  return '/' + Time.at(self.published_at).year.to_s + '/' + Time.at(self.published_at).month.to_s + '/' + self.slug
end

#tagsArray

Returns an array of the posts tags.

Returns:

  • (Array)


37
38
39
40
41
42
43
44
45
# File 'lib/blogaze/models/post.rb', line 37

def tags
  tags = []
  relationships = ::Blogaze::Models::TagsRelationship.where(:object_id => self.id, :object_type => 'post')
  relationships.each do |rel|
    tags.push rel.tag
  end

  return tags
end

#validateObject

Validations



60
61
62
63
# File 'lib/blogaze/models/post.rb', line 60

def validate
  validates_presence [:title, :body, :user_id]
  validates_integer :user_id
end