Class: Article
Constant Summary collapse
- @@tag_index =
Store list of articles for each tag in a hash Fast enough for the small number of articles we’re dealing with
{}
Instance Attribute Summary
Attributes inherited from FileModel
Class Method Summary collapse
- .archive_months ⇒ Object
- .find_articles(options = {}) ⇒ Object
- .recent(number = 5) ⇒ Object
- .tag_index ⇒ Object
- .tagged(tag) ⇒ Object
Methods inherited from FileModel
all, content_path, count, files, find, from_file, #index, #initialize, #method_missing, #next, #previous, random, relative_path
Constructor Details
This class inherits a constructor from FileModel
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FileModel
Class Method Details
.archive_months ⇒ Object
29 30 31 |
# File 'app/models/article.rb', line 29 def self.archive_months @@archive_months ||= files.map{|f| File.basename(f).split('-')[0..1] }.uniq end |
.find_articles(options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/models/article.rb', line 3 def self.find_articles( = {}) = { :per_page => 10, :page => 1 }.merge() [:offset] = ([:page]-1) * [:per_page] [:limit] = [:per_page] if [:year] and [:month] [:match] = %r(\/#{[:year]}-#{[:month].to_s.rjust(2,'0')}) end all() end |
.recent(number = 5) ⇒ Object
19 20 21 |
# File 'app/models/article.rb', line 19 def self.recent(number = 5) @@recent ||= all(:limit => number) end |
.tag_index ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'app/models/article.rb', line 36 def self.tag_index return @@tag_index if @@tag_index.present? all.each do |a| a..split(',').map(&:strip).each do |t| @@tag_index[t] ||= [] @@tag_index[t] = (@@tag_index[t] << a.key).uniq end end @@tag_index end |