diff options
author | Philip Arndt <parndt@gmail.com> | 2012-02-03 11:34:34 +1300 |
---|---|---|
committer | Philip Arndt <parndt@gmail.com> | 2012-02-03 11:34:49 +1300 |
commit | 6d06af34007fb2cf6b72c22712c3cdb6272ba110 (patch) | |
tree | 02172ecfb8f242115e9beb8283ca93ad87939dfc /app/models/refinery/blog/post.rb | |
parent | 5691a96a9dd82eea6d1927c2e607b981eb5580a8 (diff) | |
download | refinerycms-blog-6d06af34007fb2cf6b72c22712c3cdb6272ba110.tar.gz refinerycms-blog-6d06af34007fb2cf6b72c22712c3cdb6272ba110.tar.bz2 refinerycms-blog-6d06af34007fb2cf6b72c22712c3cdb6272ba110.zip |
Converted scopes to class methods.
Diffstat (limited to 'app/models/refinery/blog/post.rb')
-rw-r--r-- | app/models/refinery/blog/post.rb | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/app/models/refinery/blog/post.rb b/app/models/refinery/blog/post.rb index c119e44..5c1c6c5 100644 --- a/app/models/refinery/blog/post.rb +++ b/app/models/refinery/blog/post.rb @@ -22,7 +22,7 @@ module Refinery validates :title, :presence => true, :uniqueness => true validates :body, :presence => true - + validates :source_url, :url => { :if => 'Refinery::Blog.config.validate_source_url', :update => true, :allow_nil => true, @@ -34,24 +34,6 @@ module Refinery :approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'), :strip_non_ascii => Refinery::Setting.find_or_set(:strip_non_ascii, false, :scoping => 'blog') - scope :by_archive, lambda { |archive_date| - where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]) - } - - scope :by_year, lambda { |archive_year| - where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year]) - } - - scope :all_previous, lambda { where(['published_at <= ?', Time.now.beginning_of_month]) } - - scope :live, lambda { where( "published_at <= ? and draft = ?", Time.now, false) } - - scope :previous, lambda { |i| where(["published_at < ? and draft = ?", i.published_at, false]).limit(1) } - - scope :uncategorized, lambda { - live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } }) - } - attr_accessible :title, :body, :custom_teaser, :tag_list, :draft, :published_at, :custom_url, :author attr_accessible :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids attr_accessible :source_url, :source_url_title @@ -81,6 +63,30 @@ module Refinery end class << self + def by_archive(archive_date) + where(['published_at between ? and ?', archive_date.beginning_of_month, archive_date.end_of_month]) + end + + def by_year(archive_year) + where(['published_at between ? and ?', archive_year.beginning_of_year, archive_year.end_of_year]) + end + + def all_previous + where(['published_at <= ?', Time.now.beginning_of_month]) + end + + def live + where( "published_at <= ? and draft = ?", Time.now, false) + end + + def previous(item) + where(["published_at < ? and draft = ?", item.published_at, false]).limit(1) + end + + def uncategorized + live.includes(:categories).where(:categories => { Refinery::Categorization.table_name => { :blog_category_id => nil } }) + end + def next(current_record) self.send(:with_exclusive_scope) do where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC") |