Class: ArticleList

Inherits:
Noodall::Node
  • Object
show all
Includes:
Noodall::Articles::Archive, Noodall::Articles::Categories
Defined in:
app/models/article_list.rb

Instance Method Summary collapse

Instance Method Details

#all_categoriesObject



24
25
26
# File 'app/models/article_list.rb', line 24

def all_categories
  super(children.published.criteria.to_hash)
end

#archive(options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/article_list.rb', line 28

def archive(options = {})
  options = remove_invalid_filters(options)

  criteria = Plucky::CriteriaHash.new(
    :path => self._id,
    :_type => 'Article',
    :published_at => { :$lte => Time.zone.now },
    :published_to => { :$gte => Time.zone.now }
  ).to_hash.merge(options)

  result = self.collection.map_reduce(archive_map('published_at'), archive_reduce, {:query => criteria, :finalize => archive_finalize, :out => "tmp_articles"})
  years = result.find.to_a.map{ |hash| Year.new(hash['_id'],hash['value']) }.sort{ |a,b| b.year <=> a.year }

  years
end

#articlesObject



10
11
12
# File 'app/models/article_list.rb', line 10

def articles
  children.published
end

#listObject



20
21
22
# File 'app/models/article_list.rb', line 20

def list
  self
end

#recent_articles(options = {}) ⇒ Object



14
15
16
17
18
# File 'app/models/article_list.rb', line 14

def recent_articles(options = {})
  options = remove_invalid_filters(options)
  options[:order] = ['published_at DESC','created_at DESC']
  children.published.limit(3).all(options)
end