Skip to content

Commit

Permalink
Added ability to find posts by day, month and year.
Browse files Browse the repository at this point in the history
  • Loading branch information
RichGuk committed Oct 18, 2011
1 parent 65d6c1c commit 3c60e6f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion active_press.gemspec
Expand Up @@ -22,7 +22,8 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_dependency('activerecord', '> 3.0.0')

s.add_dependency('activesupport', '> 3.0.0')

s.add_development_dependency('rspec', '~> 2.6.0')
s.add_development_dependency('shoulda-matchers')
s.add_development_dependency('factory_girl')
Expand Down
7 changes: 7 additions & 0 deletions lib/active_press.rb
@@ -1,4 +1,11 @@
# Third Party.
require 'active_record'

# Core Extensions.
require 'active_support/core_ext/date_time/calculations'
require 'active_support/core_ext/date/calculations'
require 'active_support/core_ext/time/calculations'

require 'active_press/version'

module ActivePress
Expand Down
12 changes: 12 additions & 0 deletions lib/active_press/models/post.rb
Expand Up @@ -17,6 +17,18 @@ class ActivePress::Post < ActivePress::Base
scope :published, by_post_status('publish').before_now
scope :most_recent, order("post_date_gmt DESC")

def self.by_year(d)
where(:post_date_gmt => (d.beginning_of_year..d.end_of_year))
end

def self.by_month(d)
where(:post_date_gmt => (d.beginning_of_month..d.end_of_month))
end

def self.by_day(d)
where(:post_date_gmt => (d.beginning_of_day..d.end_of_day))
end

def to_param
post_name
end
Expand Down

0 comments on commit 3c60e6f

Please sign in to comment.