Class: Ems::Article

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/ems/article.rb

Class Method Summary collapse

Instance Method Summary collapse

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

Parameters:

  • options (defaults to: {})


104
105
106
# File 'app/models/ems/article.rb', line 104

def as_json(options={})
  super(options.merge(:include => [:category, :channels, :tags], :methods => [:image_url]))
end

#content_as_htmlObject



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_dispositionSymbol

Custom getter for content_disposition attribute to emulate ENUMs

Returns:

  • (Symbol)

    content_disposition currently assigned to the attribute



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

Parameters:

  • value (Symbol)

    to give the content_disposition attribute



90
91
92
# File 'app/models/ems/article.rb', line 90

def content_disposition= (value)
 write_attribute(:content_disposition, value.to_s)
end

#image_urlObject



98
99
100
# File 'app/models/ems/article.rb', line 98

def image_url
  self.image.url
end

#initObject

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

Returns:

  • (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

Returns:

  • (Boolean)


12
13
14
# File 'app/models/ems/article.rb', line 12

def should_generate_new_friendly_id?
  not self.is_live?
end

#statusSymbol

Custom getter for status attribute to emulate ENUMs

Returns:

  • (Symbol)

    status currently assigned to the attribute



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

Parameters:

  • value (Symbol)

    to give the status attribute



78
79
80
# File 'app/models/ems/article.rb', line 78

def status= (value)
    write_attribute(:status, value.to_s)
end