Class: Ems::Report

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_query(category = nil) ⇒ Object



106
107
108
109
110
# File 'app/models/ems/report.rb', line 106

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


99
100
101
# File 'app/models/ems/report.rb', line 99

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

#content_as_htmlObject



88
89
90
# File 'app/models/ems/report.rb', line 88

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



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

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



84
85
86
# File 'app/models/ems/report.rb', line 84

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



59
60
61
62
# File 'app/models/ems/report.rb', line 59

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

#is_live?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'app/models/ems/report.rb', line 93

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

#should_generate_new_friendly_id?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'app/models/ems/report.rb', line 6

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



66
67
68
# File 'app/models/ems/report.rb', line 66

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



72
73
74
# File 'app/models/ems/report.rb', line 72

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