From 040d7b246ef0a188f1cc490349bda83249a2d7a3 Mon Sep 17 00:00:00 2001 From: Jonathan Barrett Date: Wed, 27 Feb 2013 13:52:31 +0000 Subject: [PATCH 1/4] renames Blog#load_articles to be consistent with Article methods --- lib/chimpdoc/blog.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/chimpdoc/blog.rb b/lib/chimpdoc/blog.rb index a375122..8b5fcf6 100644 --- a/lib/chimpdoc/blog.rb +++ b/lib/chimpdoc/blog.rb @@ -48,13 +48,13 @@ def pending_articles def articles if cache - cache.fetch(CACHE_KEY) { load_articles } + cache.fetch(CACHE_KEY) { get_articles } else - load_articles + get_articles end end - def load_articles + def get_articles article_store.get_articles end From fb63a5c50dd762f99f1757844658098848808857 Mon Sep 17 00:00:00 2001 From: Jonathan Barrett Date: Wed, 27 Feb 2013 13:52:52 +0000 Subject: [PATCH 2/4] moves and reworks reload_articles to pre-load articles before caching --- lib/chimpdoc/blog.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/chimpdoc/blog.rb b/lib/chimpdoc/blog.rb index 8b5fcf6..3b551d0 100644 --- a/lib/chimpdoc/blog.rb +++ b/lib/chimpdoc/blog.rb @@ -2,14 +2,6 @@ class Chimpdoc::Blog CACHE_KEY = 'articles' - def reload_articles - if cache - cache.write(CACHE_KEY, load_articles) - else - load_articles - end - end - def cover_article feed.first end @@ -34,6 +26,13 @@ def fetch_article(slug) published_articles.find { |a| slug == a.slug } end + def refresh_articles + if cache + articles = get_articles + cache.write(CACHE_KEY, articles) + end + end + private def published_articles From 0faf49c9e4c8bce8b18f4d1728bee3a21e376cd8 Mon Sep 17 00:00:00 2001 From: Jonathan Barrett Date: Wed, 27 Feb 2013 13:53:19 +0000 Subject: [PATCH 3/4] adds TomDoc to Blog#refresh_articles --- lib/chimpdoc/blog.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/chimpdoc/blog.rb b/lib/chimpdoc/blog.rb index 3b551d0..d7f9aaa 100644 --- a/lib/chimpdoc/blog.rb +++ b/lib/chimpdoc/blog.rb @@ -26,6 +26,9 @@ def fetch_article(slug) published_articles.find { |a| slug == a.slug } end + # Public: Refresh the article cache from the store, if we have a cache specified + # + # This is designed to be called from a rake task or other automated system def refresh_articles if cache articles = get_articles From ad4de901c3ebee259ff73a51cac901995c999d2f Mon Sep 17 00:00:00 2001 From: Jonathan Barrett Date: Wed, 27 Feb 2013 14:00:09 +0000 Subject: [PATCH 4/4] adds TomDoc to all public methods on Blog --- lib/chimpdoc/blog.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/chimpdoc/blog.rb b/lib/chimpdoc/blog.rb index d7f9aaa..4cf13e5 100644 --- a/lib/chimpdoc/blog.rb +++ b/lib/chimpdoc/blog.rb @@ -2,26 +2,49 @@ class Chimpdoc::Blog CACHE_KEY = 'articles' + # Public: Retrieves the most recently published article in the blog + # + # Returns an Article def cover_article feed.first end + # Public: Returns the publication date of the next article + # + # Intended to be used to provide information to blog readers on when the next article is + # predicted to hit + # + # Returns a Date def next_article_date next_article.try(:published_on) end + # Public: Retrieves the soonest future-published article + # + # Exists primarily for use by the next_article_date method. Should probably be private + # + # Returns an Article def next_article preview_feed.first end + # Public: Retrieves all currently-published articles, ordered by latest-first + # + # Returns an Enumerable collection of Articles def feed published_articles.sort_by(&:published_on).reverse end + # Public: Retrieves all upcoming-published articles, ordered by soonest-first + # + # Returns an Enumerable collection of Articles def preview_feed pending_articles.sort_by(&:published_on) end + # Public: Retrieves a specific published article based on its slug + # + # Returns an Article def fetch_article(slug) published_articles.find { |a| slug == a.slug } end