Class: Blogaze::Models::Post
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Blogaze::Models::Post
- Defined in:
- lib/blogaze/models/post.rb
Overview
Post model
Instance Attribute Summary collapse
-
#post_tags ⇒ Object
Returns the value of attribute post_tags.
Instance Method Summary collapse
- #after_save ⇒ Object
- #before_create ⇒ Object
- #before_save ⇒ Object
-
#body_partial ⇒ String
Returns the partial body of the post.
-
#href ⇒ String
Returns the URI to the post.
-
#tags ⇒ Array
Returns an array of the posts tags.
-
#validate ⇒ Object
Validations.
Instance Attribute Details
#post_tags ⇒ Object
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_save ⇒ Object
78 79 80 |
# File 'lib/blogaze/models/post.rb', line 78 def after_save end |
#before_create ⇒ Object
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_save ⇒ Object
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_partial ⇒ String
Returns the partial body of the post.
52 53 54 55 |
# File 'lib/blogaze/models/post.rb', line 52 def body_partial body = self.body.split('<!-- MORE -->') return body[0] end |
#href ⇒ String
Returns the URI to the post.
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 |
#tags ⇒ Array
Returns an array of the posts tags.
37 38 39 40 41 42 43 44 45 |
# File 'lib/blogaze/models/post.rb', line 37 def = [] relationships = ::Blogaze::Models::TagsRelationship.where(:object_id => self.id, :object_type => 'post') relationships.each do |rel| .push rel.tag end return end |
#validate ⇒ Object
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 |