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



109
110
111
112
113
# File 'app/models/ems/article.rb', line 109

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: {})


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

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

#content_as_htmlObject



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

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



81
82
83
# File 'app/models/ems/article.rb', line 81

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



87
88
89
# File 'app/models/ems/article.rb', line 87

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

#initObject

Method to make sure we have all our default values set on the object



62
63
64
65
# File 'app/models/ems/article.rb', line 62

def init
  self.status ||= :draft
  self.content_disposition ||= :markdown
end

#is_live?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/models/ems/article.rb', line 102

def is_live?
  self.status === :live
end

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/models/ems/article.rb', line 7

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



69
70
71
# File 'app/models/ems/article.rb', line 69

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



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

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