Converted scopes to class methods.
This commit is contained in:
parent
5691a96a9d
commit
6d06af3400
2 changed files with 38 additions and 22 deletions
|
@ -17,9 +17,19 @@ module Refinery
|
||||||
validates :name, :message, :presence => true
|
validates :name, :message, :presence => true
|
||||||
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
|
validates :email, :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i }
|
||||||
|
|
||||||
scope :unmoderated, :conditions => {:state => nil}
|
class << self
|
||||||
scope :approved, :conditions => {:state => 'approved'}
|
def unmoderated
|
||||||
scope :rejected, :conditions => {:state => 'rejected'}
|
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)
|
self.per_page = Refinery::Setting.find_or_set(:blog_comments_per_page, 10)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Refinery
|
||||||
|
|
||||||
validates :title, :presence => true, :uniqueness => true
|
validates :title, :presence => true, :uniqueness => true
|
||||||
validates :body, :presence => true
|
validates :body, :presence => true
|
||||||
|
|
||||||
validates :source_url, :url => { :if => 'Refinery::Blog.config.validate_source_url',
|
validates :source_url, :url => { :if => 'Refinery::Blog.config.validate_source_url',
|
||||||
:update => true,
|
:update => true,
|
||||||
:allow_nil => true,
|
:allow_nil => true,
|
||||||
|
@ -34,24 +34,6 @@ module Refinery
|
||||||
:approximate_ascii => Refinery::Setting.find_or_set(:approximate_ascii, false, :scoping => 'blog'),
|
: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')
|
: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 :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 :browser_title, :meta_keywords, :meta_description, :user_id, :category_ids
|
||||||
attr_accessible :source_url, :source_url_title
|
attr_accessible :source_url, :source_url_title
|
||||||
|
@ -81,6 +63,30 @@ module Refinery
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
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)
|
def next(current_record)
|
||||||
self.send(:with_exclusive_scope) do
|
self.send(:with_exclusive_scope) do
|
||||||
where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")
|
where(["published_at > ? and draft = ?", current_record.published_at, false]).order("published_at ASC")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue