couch_scheduler 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -7,14 +7,14 @@ Feature: CouchPublish Integration
7
7
  Given an Article model that includes CouchPublish and CouchVisible
8
8
  When I create several published articles scheduled now and in the future
9
9
  And I create several unpublished articles scheduled now and in the future
10
- When I call "Article.by_schedule_and_published"
10
+ When I call "Article.by_schedule :published => true"
11
11
  Then I should receive the published documents scheduled now
12
- When I call "Article.by_schedule_and_unpublished"
12
+ When I call "Article.by_schedule :unpublished => true"
13
13
  Then I should receive the unpublished documents scheduled now
14
14
  When I wait till the future
15
- And I call "Article.by_schedule_and_published"
15
+ And I call "Article.by_schedule :published => true"
16
16
  Then I should receive the published documents scheduled in the future
17
- When I call "Article.by_schedule_and_unpublished"
17
+ When I call "Article.by_schedule :unpublished => true"
18
18
  Then I should receive the unpublished documents scheduled in the future
19
19
 
20
20
  @focus
@@ -24,12 +24,12 @@ Feature: CouchPublish Integration
24
24
  And I create 3 published articles schedule in the future
25
25
  And I create 4 unpublished articles scheduled now
26
26
  And I create 7 unpublished articles schedule in the future
27
- When I call "Article.count_schedule_and_published"
27
+ When I call "Article.count_schedule :published => true"
28
28
  Then I should receive 2
29
- When I call "Article.count_schedule_and_unpublished"
29
+ When I call "Article.count_schedule :unpublished => true"
30
30
  Then I should receive 4
31
31
  When I wait till the future
32
- And I call "Article.count_schedule_and_published"
32
+ And I call "Article.count_schedule :published => true"
33
33
  Then I should receive 3
34
- When I call "Article.count_schedule_and_unpublished"
34
+ When I call "Article.count_schedule :unpublished => true"
35
35
  Then I should receive 7
@@ -6,30 +6,40 @@ Feature: CouchVisible and CouchPublish Integration
6
6
  Scenario: Query for shown, published documents within a schedule
7
7
  Given a Slide model that includes CouchVisible, CouchPublish and CouchScheduler
8
8
  When I create several shown, published slides scheduled now and in the future
9
+ And I create several shown, unpublished slides scheduled now and in the future
9
10
  And I create several hidden, published slides scheduled now and in the future
10
- When I call "Slide.by_schedule_and_published_and_shown"
11
+ And I create several hidden, unpublished slides scheduled now and in the future
12
+ When I call "Slide.by_schedule :published => true, :shown => true"
11
13
  Then I should receive the shown, published documents scheduled now
12
- When I call "Slide.by_schedule_and_published_and_hidden"
14
+ When I call "Slide.by_schedule :published => true, :hidden => true"
13
15
  Then I should receive the hidden, published documents scheduled now
14
16
  When I wait till the future
15
- And I call "Slide.by_schedule_and_published_and_shown"
17
+ And I call "Slide.by_schedule :published => true, :shown => true"
16
18
  Then I should receive the shown, published documents scheduled in the future
17
- When I call "Slide.by_schedule_and_published_and_hidden"
19
+ When I call "Slide.by_schedule :published =>true, :hidden => true"
18
20
  Then I should receive the hidden, published documents scheduled in the future
19
21
 
20
22
  @focus
21
23
  Scenario: Count of shown and hidden documents within a schedule
22
24
  Given a Slide model that includes CouchVisible, CouchPublish and CouchScheduler
23
25
  When I create 2 shown, published slides scheduled now
26
+ When I create 6 shown, unpublished slides scheduled now
24
27
  And I create 3 shown, published slides schedule in the future
28
+ And I create 9 shown, unpublished slides schedule in the future
25
29
  And I create 4 hidden, published slides scheduled now
30
+ And I create 12 hidden, unpublished slides scheduled now
26
31
  And I create 7 hidden, published slides schedule in the future
27
- When I call "Slide.count_schedule_and_published_and_shown"
32
+ And I create 21 hidden, unpublished slides schedule in the future
33
+ When I call "Slide.count_schedule :published => true, :shown => true"
28
34
  Then I should receive 2
29
- When I call "Slide.count_schedule_and_published_and_hidden"
35
+ When I call "Slide.count_schedule :published => true"
36
+ Then I should receive 6
37
+ When I call "Slide.count_schedule"
38
+ Then I should receive 24
39
+ When I call "Slide.count_schedule :published =>true, :hidden => true"
30
40
  Then I should receive 4
31
41
  When I wait till the future
32
- And I call "Slide.count_schedule_and_published_and_shown"
42
+ And I call "Slide.count_schedule :published => true, :shown => true"
33
43
  Then I should receive 3
34
- When I call "Slide.count_schedule_and_published_and_hidden"
44
+ When I call "Slide.count_schedule :published =>true, :hidden => true"
35
45
  Then I should receive 7
@@ -7,14 +7,14 @@ Feature: CouchVisible Integration
7
7
  Given an Post model that includes CouchVisible and CouchScheduler
8
8
  When I create several shown posts scheduled now and in the future
9
9
  And I create several hidden posts scheduled now and in the future
10
- When I call "Post.by_schedule_and_shown"
10
+ When I call "Post.by_schedule :shown => true"
11
11
  Then I should receive the shown documents scheduled now
12
- When I call "Post.by_schedule_and_hidden"
12
+ When I call "Post.by_schedule :hidden => true"
13
13
  Then I should receive the hidden documents scheduled now
14
14
  When I wait till the future
15
- And I call "Post.by_schedule_and_shown"
15
+ And I call "Post.by_schedule :shown => true"
16
16
  Then I should receive the shown documents scheduled in the future
17
- When I call "Post.by_schedule_and_hidden"
17
+ When I call "Post.by_schedule :hidden => true"
18
18
  Then I should receive the hidden documents scheduled in the future
19
19
 
20
20
  @focus
@@ -24,12 +24,12 @@ Feature: CouchVisible Integration
24
24
  And I create 3 shown posts schedule in the future
25
25
  And I create 4 hidden posts scheduled now
26
26
  And I create 7 hidden posts schedule in the future
27
- When I call "Post.count_schedule_and_shown"
27
+ When I call "Post.count_schedule :shown => true"
28
28
  Then I should receive 2
29
- When I call "Post.count_schedule_and_hidden"
29
+ When I call "Post.count_schedule :hidden => true"
30
30
  Then I should receive 4
31
31
  When I wait till the future
32
- And I call "Post.count_schedule_and_shown"
32
+ And I call "Post.count_schedule :shown => true"
33
33
  Then I should receive 3
34
- When I call "Post.count_schedule_and_hidden"
34
+ When I call "Post.count_schedule :hidden => true"
35
35
  Then I should receive 7
@@ -16,6 +16,15 @@ When /^I create several shown, published slides scheduled now and in the future$
16
16
  5.times { @published_shown_future << Slide.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.show!; a.publish! } }
17
17
  end
18
18
 
19
+ When /^I create several shown, unpublished slides scheduled now and in the future$/ do
20
+ @unpublished_shown_now = []
21
+ @unpublished_shown_future = []
22
+
23
+ 5.times { @unpublished_shown_now << Slide.create(:start => Time.now, :end => 1.day.from_now).tap {|a| a.show!} }
24
+ 5.times { @unpublished_shown_future << Slide.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.show!} }
25
+ end
26
+
27
+
19
28
  When /^I create several hidden, published slides scheduled now and in the future$/ do
20
29
  @published_hidden_now = []
21
30
  @published_hidden_future = []
@@ -24,6 +33,14 @@ When /^I create several hidden, published slides scheduled now and in the future
24
33
  5.times { @published_hidden_future << Slide.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.hide!; a.publish! } }
25
34
  end
26
35
 
36
+ When /^I create several hidden, unpublished slides scheduled now and in the future$/ do
37
+ @unpublished_hidden_now = []
38
+ @unpublished_hidden_future = []
39
+
40
+ 5.times { @unpublished_hidden_now << Slide.create(:start => Time.now, :end => 1.day.from_now).tap {|a| a.hide! } }
41
+ 5.times { @unpublished_hidden_future << Slide.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.hide! } }
42
+ end
43
+
27
44
  Then /^I should receive the shown, published documents scheduled now$/ do
28
45
  @result.collect(&:id).sort.should == @published_shown_now.collect(&:id).sort
29
46
  end
@@ -59,3 +76,23 @@ When /^I create (\d+) hidden, published slides schedule in the future$/ do |num|
59
76
  @published_hidden_future = []
60
77
  num.to_i.times { @published_hidden_future << Slide.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.hide!; a.publish!}}
61
78
  end
79
+
80
+ When /^I create (\d+) shown, unpublished slides scheduled now$/ do |num|
81
+ @unpublished_shown_future = []
82
+ num.to_i.times { @unpublished_shown_future << Slide.create(:start => Time.now, :end => 1.day.from_now).tap {|a| a.show!}}
83
+ end
84
+
85
+ When /^I create (\d+) shown, unpublished slides schedule in the future$/ do |num|
86
+ @unpublished_shown_future = []
87
+ num.to_i.times { @unpublished_shown_future << Slide.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.show!}}
88
+ end
89
+
90
+ When /^I create (\d+) hidden, unpublished slides scheduled now$/ do |num|
91
+ @unpublished_hidden_now = []
92
+ num.to_i.times { @unpublished_hidden_now << Slide.create(:start => Time.now, :end => 1.day.from_now).tap {|a| a.hide!}}
93
+ end
94
+
95
+ When /^I create (\d+) hidden, unpublished slides schedule in the future$/ do |num|
96
+ @unpublished_hidden_future = []
97
+ num.to_i.times { @unpublished_hidden_future << Slide.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.hide!}}
98
+ end
@@ -1,5 +1,5 @@
1
1
  require 'couchrest_model'
2
- require 'couch_scheduler/time_massager'
2
+ require 'couch_scheduler/options'
3
3
  require 'couch_scheduler/map'
4
4
  require 'couch_scheduler/couch_visible_integration'
5
5
  require 'couch_scheduler/couch_publish_integration'
@@ -2,25 +2,24 @@ module CouchScheduler
2
2
  module CouchVisibleCouchPublishIntegration
3
3
  def self.included(base)
4
4
  base.extend ClassMethods
5
- base.view_by :couch_schedule_and_published_and_shown, :map => Map.new(base, :published, :shown).to_s, :reduce => '_count'
5
+ base.view_by :couch_schedule_and_published_and_shown, :map => Map.new(base, :published, :shown).to_s, :reduce => '_count'
6
6
  base.view_by :couch_schedule_and_published_and_hidden, :map => Map.new(base, :published, :hidden).to_s, :reduce => '_count'
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def by_schedule_and_published_and_shown(options={})
11
- by_couch_schedule_and_shown CouchScheduler::TimeMassager.massage(options)
12
- end
13
-
14
- def by_schedule_and_published_and_hidden(options={})
15
- by_couch_schedule_and_hidden CouchScheduler::TimeMassager.massage(options)
16
- end
17
-
18
- def count_schedule_and_published_and_shown(options={})
19
- count_by_map :by_schedule_and_published_and_shown, options
20
- end
10
+ def by_schedule(options={})
11
+ shown = options[:shown]
12
+ hidden = options[:hidden]
13
+ published = options[:published]
14
+ unpublished = options[:unpublished]
21
15
 
22
- def count_schedule_and_published_and_hidden(options={})
23
- count_by_map :by_schedule_and_published_and_hidden, options
16
+ if shown == true && published == true
17
+ by_couch_schedule_and_published_and_shown CouchScheduler::Options.new(options).to_hash
18
+ elsif hidden == true && published == true
19
+ by_couch_schedule_and_published_and_hidden CouchScheduler::Options.new(options).to_hash
20
+ else
21
+ super
22
+ end
24
23
  end
25
24
  end
26
25
  end
@@ -3,24 +3,21 @@ module CouchScheduler
3
3
  def self.included(base)
4
4
  base.extend ClassMethods
5
5
  base.view_by :couch_schedule_and_unpublished, :map => Map.new(base, :unpublished).to_s, :reduce => '_count'
6
- base.view_by :couch_schedule_and_published, :map => Map.new(base, :published).to_s, :reduce => '_count'
6
+ base.view_by :couch_schedule_and_published, :map => Map.new(base, :published).to_s, :reduce => '_count'
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def by_schedule_and_published(options={})
11
- by_couch_schedule_and_published CouchScheduler::TimeMassager.massage(options)
12
- end
13
-
14
- def by_schedule_and_unpublished(options={})
15
- by_couch_schedule_and_unpublished CouchScheduler::TimeMassager.massage(options)
16
- end
17
-
18
- def count_schedule_and_published(options={})
19
- count_by_map :by_schedule_and_published, options
20
- end
10
+ def by_schedule(options={})
11
+ published = options[:published]
12
+ unpublished = options[:unpublished]
21
13
 
22
- def count_schedule_and_unpublished(options={})
23
- count_by_map :by_schedule_and_unpublished, options
14
+ if published == true || unpublished == false
15
+ by_couch_schedule_and_published CouchScheduler::Options.new(options).to_hash
16
+ elsif unpublished == true || published == false
17
+ by_couch_schedule_and_unpublished CouchScheduler::Options.new(options).to_hash
18
+ else
19
+ super
20
+ end
24
21
  end
25
22
  end
26
23
  end
@@ -21,7 +21,7 @@ module CouchScheduler
21
21
 
22
22
  module ClassMethods
23
23
  def by_schedule(options={})
24
- by_couch_schedule CouchScheduler::TimeMassager.massage(options)
24
+ by_couch_schedule CouchScheduler::Options.new(options).to_hash
25
25
  end
26
26
 
27
27
  def count_schedule(options={})
@@ -7,20 +7,17 @@ module CouchScheduler
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def by_schedule_and_shown(options={})
11
- by_couch_schedule_and_shown CouchScheduler::TimeMassager.massage(options)
12
- end
13
-
14
- def by_schedule_and_hidden(options={})
15
- by_couch_schedule_and_hidden CouchScheduler::TimeMassager.massage(options)
16
- end
17
-
18
- def count_schedule_and_shown(options={})
19
- count_by_map :by_schedule_and_shown, options
20
- end
10
+ def by_schedule(options={})
11
+ shown = options.delete :shown
12
+ hidden = options.delete :hidden
21
13
 
22
- def count_schedule_and_hidden(options={})
23
- count_by_map :by_schedule_and_hidden, options
14
+ if shown == true || hidden == false
15
+ by_couch_schedule_and_shown CouchScheduler::Options.new(options).to_hash
16
+ elsif hidden == true || shown == false
17
+ by_couch_schedule_and_hidden CouchScheduler::Options.new(options).to_hash
18
+ else
19
+ super
20
+ end
24
21
  end
25
22
  end
26
23
  end
@@ -1,7 +1,14 @@
1
1
  module CouchScheduler
2
- module TimeMassager
3
- extend self
2
+ class Options
3
+ def initialize(options)
4
+ @options = massage options.dup
5
+ end
4
6
 
7
+ def to_hash
8
+ @options
9
+ end
10
+
11
+ private
5
12
  def massage(options)
6
13
  if !options[:startkey] && !options[:key]
7
14
  options = {:key => format_time(Time.now), :reduce => false}.merge options
@@ -11,10 +18,14 @@ module CouchScheduler
11
18
  options[option] = format_time options[option] if options[option].kind_of?(Time)
12
19
  end
13
20
 
21
+ options.delete :shown
22
+ options.delete :hidden
23
+ options.delete :published
24
+ options.delete :unpublished
25
+
14
26
  options
15
27
  end
16
28
 
17
- private
18
29
  def format_time(t)
19
30
  [t.year, t.month - 1, t.day, 0, 0, 0]
20
31
  end
data/readme.markdown CHANGED
@@ -25,6 +25,7 @@ You can now provide start and end dates for your articles:
25
25
  @article.end = 6.days.from_now
26
26
  @article.save
27
27
 
28
+
28
29
  ## Validation
29
30
 
30
31
  `CouchSchedule` will use `ActiveModel` validation to ensure that your `end` is after your `start`:
@@ -34,6 +35,7 @@ You can now provide start and end dates for your articles:
34
35
  @article.save #==> false
35
36
  @artile.errors #==> [:end, " must be greater than start"]
36
37
 
38
+
37
39
  ## Uses?
38
40
 
39
41
  Now what can you do with these start and end dates? One use: publishing.
@@ -46,6 +48,8 @@ Let's imagine that you only to display this article on your website between the
46
48
 
47
49
  @article.within_schedule? #==> false
48
50
 
51
+ ### Query (.by_schedule)
52
+
49
53
  You can also query the databases for all of the articles currently within their schedule via `by_schedule`:
50
54
 
51
55
  Article.by_schedule
@@ -68,54 +72,52 @@ Like `by_schedule`, `count_schedule` supports all the usual map/reduce options:
68
72
  Article.count_schedule :key => 10.days.from_now
69
73
  #==> the count of all articles that are within their start/end dates 10 days from now
70
74
 
75
+
71
76
  ## CouchPublish Integration
72
77
 
73
- If you include `CouchScheduler` into a model that already includes `CouchPublish`, then you get a new map function for free, `by_schedule_and_published`:
78
+ If you include `CouchScheduler` into a model that already includes `CouchPublish`, then you can pass `:publish => true` and `:unpublish => true`:
74
79
 
75
80
  # with a class definition like this:
76
81
  class Article < CouchRest::Model::Base
77
82
  include CouchPublish
78
83
  include CouchScheduler
84
+
79
85
  property :title
80
86
  end
81
87
 
82
88
  # you can query for all published and currently scheduled documents like this:
83
- Article.by_schedule_and_published
89
+ Article.by_schedule :published => true
84
90
  #==> returns all documents that are published and currently within their schedule
85
91
 
86
92
  # you can also query for the unpublished and currently scheduled documents like this:
87
- Article.by_schedule_and_unpublished
93
+ Article.by_schedule :unpublished => true
94
+
95
+ You can also pass `:published => true` and `:unpublished => true` to the `count_schedule` method.
88
96
 
89
- You'll also get `count_schedule_and_published` and `count_schedule_and_unpublished` for free.
90
97
 
91
98
  ## CouchVisible Integration
92
99
 
93
100
  If you include `CouchScheduler` into a model that includes `CouchVisible`, you'll get the following map/reduce functions for free:
94
101
 
95
- Article.by_schedule_and_shown
102
+ Article.by_schedule :shown => true
96
103
  #==> all articles that are currently within their start and end dates and are shown
97
104
 
98
- Article.by_schedule_and_hidden
105
+ Article.by_schedule :hidden => true
99
106
  #==> all articles that are currently within their start and end dates and are hidden
100
107
 
101
- Article.count_schedule_and_shown
102
- Article.count_schedule_and_hidden
103
-
104
- ## CouchPublish/CouchVisible integration
108
+ Article.count_schedule :shown => true
109
+ Article.count_schedule :hidden => true
105
110
 
106
- If you include `CouchScheduler` into a model that includes both `CouchVisible` and `CouchPublish`, you'll get the following map/reduce functions for free:
107
111
 
108
- Article.by_schedule_and_published_and_shown
109
- Article.by_schedule_and_published_and_hidden
110
- Article.by_schedule_and_unpublished_and_shown
111
- Article.by_schedule_and_unpublished_and_hidden
112
+ ## CouchPublish/CouchVisible integration
112
113
 
113
- And of course, all the corresponding `count` methods are available:
114
+ If you include `CouchScheduler` into a model that includes both `CouchVisible` and `CouchPublish`, you can pass `:published => true`, `:unpublished => true`, `:shown => true`, `:hidden => true` to your schedule query methods:
114
115
 
115
- Article.count_schedule_and_published_and_shown
116
- Article.count_schedule_and_published_and_hidden
117
- Article.count_schedule_and_unpublished_and_shown
118
- Article.count_schedule_and_unpublished_and_hidden
116
+ Article.by_schedule :published => true, :shown => true
117
+ Article.by_schedule :unpublished => true, :hidden => true
118
+ Article.count_schedule :published => true, :shown => true
119
+ Article.count_schedule :unpublished => true, :hidden => true
120
+
119
121
 
120
122
  ## LICENSE
121
123
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couch_scheduler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matt Parker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-20 00:00:00 Z
18
+ date: 2011-07-23 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: cucumber
@@ -133,7 +133,7 @@ files:
133
133
  - lib/couch_scheduler/couch_scheduler.rb
134
134
  - lib/couch_scheduler/couch_visible_integration.rb
135
135
  - lib/couch_scheduler/map.rb
136
- - lib/couch_scheduler/time_massager.rb
136
+ - lib/couch_scheduler/options.rb
137
137
  - lib/couch_scheduler.rb
138
138
  - VERSION
139
139
  - readme.markdown