Class: Ems::Article
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ems::Article
- Extended by:
- FriendlyId
- Defined in:
- app/models/ems/article.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #content_as_html ⇒ Object
-
#content_disposition ⇒ Symbol
Custom getter for content_disposition attribute to emulate ENUMs.
-
#content_disposition=(value) ⇒ Object
Custom setter for content_disposition attribute to emulate ENUMs.
- #image_url ⇒ Object
-
#init ⇒ Object
Method to make sure we have all our default values set on the object.
- #is_live? ⇒ Boolean
- #should_generate_new_friendly_id? ⇒ Boolean
-
#status ⇒ Symbol
Custom getter for status attribute to emulate ENUMs.
-
#status=(value) ⇒ Object
Custom setter for status attribute to emulate ENUMs.
Class Method Details
.base_query(category = nil) ⇒ Object
116 117 118 119 120 |
# File 'app/models/ems/article.rb', line 116 def base_query(category=nil) q = self.joins(:category).where("publish_from <= :publish_from", {:publish_from => Time.now.strftime("%Y/%m/%d %H:00:00")}).where(:status => 'live') q = q.where('ems_categories.id' => category.id) if category return q end |
Instance Method Details
#as_json(options = {}) ⇒ Object
104 105 106 |
# File 'app/models/ems/article.rb', line 104 def as_json(={}) super(.merge(:include => [:category, :channels, :tags], :methods => [:image_url])) end |
#content_as_html ⇒ Object
94 95 96 |
# File 'app/models/ems/article.rb', line 94 def content_as_html Kramdown::Document.new(content, :input => "BeanKramdown").to_html end |
#content_disposition ⇒ Symbol
Custom getter for content_disposition attribute to emulate ENUMs
84 85 86 |
# File 'app/models/ems/article.rb', line 84 def content_disposition read_attribute(:content_disposition).to_sym if read_attribute :content_disposition end |
#content_disposition=(value) ⇒ Object
Custom setter for content_disposition attribute to emulate ENUMs
90 91 92 |
# File 'app/models/ems/article.rb', line 90 def content_disposition= (value) write_attribute(:content_disposition, value.to_s) end |
#image_url ⇒ Object
98 99 100 |
# File 'app/models/ems/article.rb', line 98 def image_url self.image.url end |
#init ⇒ Object
Method to make sure we have all our default values set on the object
65 66 67 68 |
# File 'app/models/ems/article.rb', line 65 def init self.status ||= :draft self.content_disposition ||= :markdown end |
#is_live? ⇒ Boolean
109 110 111 |
# File 'app/models/ems/article.rb', line 109 def is_live? self.status === :live end |
#should_generate_new_friendly_id? ⇒ Boolean
12 13 14 |
# File 'app/models/ems/article.rb', line 12 def should_generate_new_friendly_id? not self.is_live? end |
#status ⇒ Symbol
Custom getter for status attribute to emulate ENUMs
72 73 74 |
# File 'app/models/ems/article.rb', line 72 def status read_attribute(:status).to_sym if read_attribute :status end |
#status=(value) ⇒ Object
Custom setter for status attribute to emulate ENUMs
78 79 80 |
# File 'app/models/ems/article.rb', line 78 def status= (value) write_attribute(:status, value.to_s) end |