Converted scopes to class methods.

This commit is contained in:
Philip Arndt 2012-02-03 11:34:34 +13:00
parent 5691a96a9d
commit 6d06af3400
2 changed files with 38 additions and 22 deletions

View file

@ -17,9 +17,19 @@ module Refinery
validates :name, :message, :presence => true
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
scope :unmoderated, :conditions => {:state => nil}
scope :approved, :conditions => {:state => 'approved'}
scope :rejected, :conditions => {:state => 'rejected'}
class << self
def unmoderated
where(:state => nil)
end
def approved
where(:state => 'approved')
end
def rejected
where(:state => 'rejected')
end
end
self.per_page = Refinery::Setting.find_or_set(:blog_comments_per_page, 10)

View file

@ -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")