Class: C::Blog

Inherits:
ApplicationRecord show all
Includes:
Authorable, Imageable, Previewable, SitePage
Defined in:
app/models/c/blog.rb

Constant Summary collapse

INDEX_TABLE =
{
  "Name": { link: { name: { call: 'name' }, options: '[:edit, object]' }, sort: 'name' },
  "Author": { call: 'author', sort: 'author' },
  "Published": { call: 'published', sort: 'published' },
  "Created": { call: 'created_at', sort: 'published' },
  "Edit": { link: { name: { text: 'edit' }, options: '[:edit, object]' } }
}.freeze

Class Method Summary collapse

Class Method Details

.created_in_date_range(start_date, end_date, options = {}) ⇒ Object



13
14
15
16
# File 'app/models/c/blog.rb', line 13

def self.created_in_date_range(start_date, end_date, options = {})
  limit = options.delete(:limit)
  Blog.where(created_at: start_date...end_date).limit(limit)
end

.created_in_month(options = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'app/models/c/blog.rb', line 18

def self.created_in_month(options = {})
  year = options[:year] || Time.now.year
  month = options[:month] || Time.now.month
  limit = options[:limit]
  date_start = Time.new(year, month, 1, 0, 0, 0)
  date_end = date_start.advance(months: 1)
  created_in_date_range(date_start, date_end, limit: limit)
end

.created_in_year(options = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'app/models/c/blog.rb', line 27

def self.created_in_year(options = {})
  year = options[:year] || Time.now.year
  limit = options[:limit]
  date_start = Time.new(year, 1, 1, 0, 0, 0)
  date_end = date_start.advance(years: 1)
  created_in_date_range(date_start, date_end, limit: limit)
end