active_press 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/active_press.gemspec CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.require_paths = ["lib"]
23
23
 
24
24
  s.add_dependency('activerecord', '> 3.0.0')
25
-
25
+ s.add_dependency('activesupport', '> 3.0.0')
26
+
26
27
  s.add_development_dependency('rspec', '~> 2.6.0')
27
28
  s.add_development_dependency('shoulda-matchers')
28
29
  s.add_development_dependency('factory_girl')
data/lib/active_press.rb CHANGED
@@ -1,4 +1,11 @@
1
+ # Third Party.
1
2
  require 'active_record'
3
+
4
+ # Core Extensions.
5
+ require 'active_support/core_ext/date_time/calculations'
6
+ require 'active_support/core_ext/date/calculations'
7
+ require 'active_support/core_ext/time/calculations'
8
+
2
9
  require 'active_press/version'
3
10
 
4
11
  module ActivePress
@@ -1,8 +1,8 @@
1
1
  class ActivePress::Post < ActivePress::Base
2
2
  set_table_name "wp_posts"
3
3
  set_primary_key "ID"
4
-
5
- has_many :comments, :foreign_key => "comment_post_ID"
4
+
5
+ has_many :comments, :foreign_key => "comment_post_ID", :order => 'comment_date_gmt DESC'
6
6
  has_many :postmetas, :foreign_key => "post_id"
7
7
  has_many :term_relationships, :foreign_key => "object_id"
8
8
  has_many :term_taxonomies, :through => :term_relationships
@@ -16,15 +16,41 @@ class ActivePress::Post < ActivePress::Base
16
16
  scope :before_now, lambda { where("post_date_gmt < ?", Time.now.to_s(:db)) }
17
17
  scope :published, by_post_status('publish').before_now
18
18
  scope :most_recent, order("post_date_gmt DESC")
19
-
19
+
20
+ def self.by_year(d)
21
+ where(:post_date_gmt => (d.beginning_of_year..d.end_of_year))
22
+ end
23
+
24
+ def self.by_month(d)
25
+ where(:post_date_gmt => (d.beginning_of_month..d.end_of_month))
26
+ end
27
+
28
+ def self.by_day(d)
29
+ where(:post_date_gmt => (d.beginning_of_day..d.end_of_day))
30
+ end
31
+
32
+ def next_post
33
+ self.class.published.where(['id != ?', self.id])\
34
+ .where(:post_type => self.post_type)\
35
+ .where(['post_date_gmt >= ?', self.post_date_gmt])\
36
+ .order('post_date_gmt ASC').limit(1)
37
+ end
38
+
39
+ def previous_post
40
+ self.class.published.where(['id != ?', self.id])\
41
+ .where(:post_type => self.post_type)\
42
+ .where(['post_date_gmt <= ?', self.post_date_gmt])\
43
+ .order('post_date_gmt DESC').limit(1)
44
+ end
45
+
20
46
  def to_param
21
47
  post_name
22
48
  end
23
-
49
+
24
50
  def meta
25
51
  postmetas.inject({}) do |hash, postmeta|
26
52
  hash[postmeta.meta_key.to_sym] = postmeta.meta_value
27
53
  hash
28
54
  end
29
55
  end
30
- end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module ActivePress
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_press
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-10-13 00:00:00.000000000 Z
13
+ date: 2011-10-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &70105711649720 !ruby/object:Gem::Requirement
17
+ requirement: &70333281740500 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>'
@@ -22,10 +22,21 @@ dependencies:
22
22
  version: 3.0.0
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70105711649720
25
+ version_requirements: *70333281740500
26
+ - !ruby/object:Gem::Dependency
27
+ name: activesupport
28
+ requirement: &70333281739760 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>'
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70333281739760
26
37
  - !ruby/object:Gem::Dependency
27
38
  name: rspec
28
- requirement: &70105711649060 !ruby/object:Gem::Requirement
39
+ requirement: &70333281738940 !ruby/object:Gem::Requirement
29
40
  none: false
30
41
  requirements:
31
42
  - - ~>
@@ -33,10 +44,10 @@ dependencies:
33
44
  version: 2.6.0
34
45
  type: :development
35
46
  prerelease: false
36
- version_requirements: *70105711649060
47
+ version_requirements: *70333281738940
37
48
  - !ruby/object:Gem::Dependency
38
49
  name: shoulda-matchers
39
- requirement: &70105711648460 !ruby/object:Gem::Requirement
50
+ requirement: &70333281738480 !ruby/object:Gem::Requirement
40
51
  none: false
41
52
  requirements:
42
53
  - - ! '>='
@@ -44,10 +55,10 @@ dependencies:
44
55
  version: '0'
45
56
  type: :development
46
57
  prerelease: false
47
- version_requirements: *70105711648460
58
+ version_requirements: *70333281738480
48
59
  - !ruby/object:Gem::Dependency
49
60
  name: factory_girl
50
- requirement: &70105711647620 !ruby/object:Gem::Requirement
61
+ requirement: &70333281737720 !ruby/object:Gem::Requirement
51
62
  none: false
52
63
  requirements:
53
64
  - - ! '>='
@@ -55,10 +66,10 @@ dependencies:
55
66
  version: '0'
56
67
  type: :development
57
68
  prerelease: false
58
- version_requirements: *70105711647620
69
+ version_requirements: *70333281737720
59
70
  - !ruby/object:Gem::Dependency
60
71
  name: sqlite3
61
- requirement: &70105711646900 !ruby/object:Gem::Requirement
72
+ requirement: &70333281736960 !ruby/object:Gem::Requirement
62
73
  none: false
63
74
  requirements:
64
75
  - - ! '>='
@@ -66,7 +77,7 @@ dependencies:
66
77
  version: '0'
67
78
  type: :development
68
79
  prerelease: false
69
- version_requirements: *70105711646900
80
+ version_requirements: *70333281736960
70
81
  description: ! "\n ActivePress is a set of tools that help with accessing and\n
71
82
  \ manipulating the contents of a Wordpress database using Ruby.\n "
72
83
  email: