acts_as_event_owner 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.textile CHANGED
@@ -1,6 +1,6 @@
1
1
  h1. ActsAsEventOwner
2
2
 
3
- ActsAsEventOwner is an ActiveRecord extension that adds calendar event management to any ActiveRecord model. Models that declare themselves as @acts_as_event_owner@ gain two @has_many@ associations- one for the event specifications, and one for the event occurrences.
3
+ ActsAsEventOwner is an ActiveRecord extension that adds calendar event management to any ActiveRecord model. Models that declare themselves as @acts_as_event_owner@ gain two @has_many@ associations- one for the event specifications, and one for the event occurrences.
4
4
 
5
5
  ActsAsEventOwner supports recurring events, with roughly the same recurrence rule capabilities as Apple's iCal application. Under the hood, ActsAsEventOwner uses "ri_cal":http://github.com/rubyredrick/ri_cal to provide recurring event support.
6
6
 
@@ -8,7 +8,7 @@ h1. Installation
8
8
 
9
9
  h2. Rails 2.3.x
10
10
 
11
- ActsAsEventOwner is available both as a gem and as a plugin.
11
+ ActsAsEventOwner is available both as a gem and as a plugin.
12
12
 
13
13
  h3. Installing as a Rails 2.3.x plugin
14
14
 
@@ -53,7 +53,7 @@ Then do:
53
53
 
54
54
  <pre>
55
55
  bundle install
56
- ~</pre>
56
+ </pre>
57
57
 
58
58
  h3. Rails 3 post-installation steps
59
59
 
@@ -70,22 +70,25 @@ h1. Usage
70
70
  class User < ActiveRecord::Base
71
71
  acts_as_event_owner
72
72
  end
73
-
73
+
74
74
  @user = User.create :name => 'Alvin Seville'
75
- @user.event_specifications.create :description => 'acquire cheese balls',
76
- :start_at => Date.today.to_time.utc,
75
+ @user.event_specifications.create :description => 'acquire cheese balls',
76
+ :start_at => Date.today.to_time.utc,
77
77
  :repeat => :daily,
78
78
  :generate => false
79
-
79
+
80
80
  @user.events # => []
81
-
81
+
82
82
  @user.events.generate :from => Date.today.to_time.utc, :to => Date.today.to_time.utc + 1.week
83
-
83
+
84
84
  # override the description on a per-generate basis
85
- @user.events.generate :from => Date.today.to_time.utc, :to => Date.today.to_time.utc + 1.week,
85
+ @user.events.generate :from => Date.today.to_time.utc - 1.day, :to => Date.today.to_time.utc + 1.week,
86
86
  :attributes => { :description => 'acquire cheese balls, like, right away!' }
87
-
88
- @user.events # => (7 ActsAsEventOwner::EventOccurrence objects)
87
+
88
+ @user.events # => (8 ActsAsEventOwner::EventOccurrence objects)
89
+
90
+ @user.events.past # => (1 ActsAsEventOwner::EventOccurrence objects)
91
+ @user.events.upcoming #=> (7 ActsAsEventOwner::EventOccurrence objects)
89
92
  </pre>
90
93
 
91
94
  h2. Adding custom fields
@@ -103,92 +106,92 @@ ActsAsEventOwner supports recurrence rules roughly equivalent to those supported
103
106
  h3. One-time event
104
107
 
105
108
  <pre>
106
- EventSpecification.create :description => 'pick up laundry',
109
+ EventSpecification.create :description => 'pick up laundry',
107
110
  :start_at => Time.parse("4:00pm")
108
111
  </pre>
109
112
 
110
113
  h3. Every day
111
114
 
112
115
  <pre>
113
- EventSpecification.create :description => 'eat breakfast',
114
- :start_at => Time.parse("7:30am"),
116
+ EventSpecification.create :description => 'eat breakfast',
117
+ :start_at => Time.parse("7:30am"),
115
118
  :repeat => :daily
116
119
  </pre>
117
120
 
118
121
  h3. Every three days
119
122
 
120
123
  <pre>
121
- EventSpecification.create :description => 'call mom',
122
- :start_at => Time.parse("10:30am"),
123
- :repeat => :daily,
124
+ EventSpecification.create :description => 'call mom',
125
+ :start_at => Time.parse("10:30am"),
126
+ :repeat => :daily,
124
127
  :frequency => 3
125
128
  </pre>
126
129
 
127
130
  h3. On Monday, Wednesday, and Friday of each week
128
131
 
129
132
  <pre>
130
- EventSpecification.create :description => 'go to the gym',
131
- :start_at => Time.parse("6:30am"),
132
- :repeat => :weekly,
133
+ EventSpecification.create :description => 'go to the gym',
134
+ :start_at => Time.parse("6:30am"),
135
+ :repeat => :weekly,
133
136
  :on => [ :mo, :we, :fr ]
134
137
  </pre>
135
138
 
136
139
  h3. On Thursday, every other week
137
140
 
138
141
  <pre>
139
- EventSpecification.create :description => 'clean the bathroom',
140
- :start_at => Time.parse("8:00pm"),
141
- :repeat => :weekly,
142
+ EventSpecification.create :description => 'clean the bathroom',
143
+ :start_at => Time.parse("8:00pm"),
144
+ :repeat => :weekly,
142
145
  :frequency => 2, :on => [ :th ]
143
146
  </pre>
144
147
 
145
148
  h3. On the 10th and 25th of each month
146
149
 
147
150
  <pre>
148
- EventSpecification.create :description => 'pick up paycheck',
149
- :start_at => Time.parse("9:30am"),
150
- :repeat => :monthly,
151
+ EventSpecification.create :description => 'pick up paycheck',
152
+ :start_at => Time.parse("9:30am"),
153
+ :repeat => :monthly,
151
154
  :on => [ 10, 25 ]
152
155
  </pre>
153
156
 
154
157
  h3. On the last Saturday of each month
155
158
 
156
159
  <pre>
157
- EventSpecification.create :description => 'run a marathon',
158
- :start_at => Time.parse("6:30am"),
159
- :repeat => :monthly,
160
- :on_the => :last,
160
+ EventSpecification.create :description => 'run a marathon',
161
+ :start_at => Time.parse("6:30am"),
162
+ :repeat => :monthly,
163
+ :on_the => :last,
161
164
  :target => [ :sa ]
162
165
  </pre>
163
166
 
164
167
  h3. On the last weekday of each month
165
168
 
166
169
  <pre>
167
- EventSpecification.create :description => 'wine tasting',
168
- :start_at => Time.parse("6:30pm"),
169
- :repeat => :monthly,
170
- :on_the => :last,
170
+ EventSpecification.create :description => 'wine tasting',
171
+ :start_at => Time.parse("6:30pm"),
172
+ :repeat => :monthly,
173
+ :on_the => :last,
171
174
  :target => :wkday
172
175
  </pre>
173
176
 
174
177
  h3. Every April 15th
175
178
 
176
179
  <pre>
177
- EventSpecification.create :description => 'pay taxes',
178
- :start_at => Time.parse("4/15/2010 5:00pm"),
180
+ EventSpecification.create :description => 'pay taxes',
181
+ :start_at => Time.parse("4/15/2010 5:00pm"),
179
182
  :repeat => :yearly
180
183
  </pre>
181
184
 
182
185
  h3. On the second Thursday in May, every other year, until Dec 31, 2012
183
186
 
184
187
  <pre>
185
- EventSpecification.create :description => 'freak out',
186
- :start_at => Time.now.utc,
187
- :repeat => :yearly,
188
- :frequency => 2,
189
- :on => [ 5 ],
190
- :on_the => :second,
191
- :target => [ :th ],
188
+ EventSpecification.create :description => 'freak out',
189
+ :start_at => Time.now.utc,
190
+ :repeat => :yearly,
191
+ :frequency => 2,
192
+ :on => [ 5 ],
193
+ :on_the => :second,
194
+ :target => [ :th ],
192
195
  :until => Time.parse("12/31/2012")
193
196
  </pre>
194
197
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_event_owner}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Danny Burkes"]
12
- s.date = %q{2010-10-17}
12
+ s.date = %q{2010-11-27}
13
13
  s.description = %q{Simple calendar events for any ActiveRecord model}
14
14
  s.email = %q{dburkes@netable.com}
15
15
  s.extra_rdoc_files = [
@@ -3,7 +3,7 @@ module ActsAsEventOwner
3
3
  def self.included(base)
4
4
  base.send :extend, ClassMethods
5
5
  end
6
-
6
+
7
7
  module ClassMethods
8
8
  def acts_as_event_owner options = {}
9
9
  include InstanceMethods
@@ -15,18 +15,26 @@ module ActsAsEventOwner
15
15
  proxy_owner.event_specifications.find(:all, :conditions => "until IS NULL OR until >= '#{Time.now.utc.to_s(:db)}'").each {|spec| spec.generate_events(options)}
16
16
  self.reload
17
17
  end
18
-
18
+
19
19
  def <<(obj)
20
20
  raise ActsAsEventOwner::Exception.new("Do not add events directly- add event specifications, then call events.generate")
21
21
  end
22
-
22
+
23
23
  def build(attributes={})
24
24
  raise ActsAsEventOwner::Exception.new("Do not build events directly- build event specifications, then call events.generate")
25
25
  end
26
-
26
+
27
27
  def create(attributes={})
28
28
  raise ActsAsEventOwner::Exception.new("Do not create events directly- build event specifications, then call events.generate")
29
29
  end
30
+
31
+ def upcoming
32
+ find(:all, :conditions => ["start_at >= ?", Time.now.utc])
33
+ end
34
+
35
+ def past
36
+ find(:all, :conditions => ["start_at < ?", Time.now.utc])
37
+ end
30
38
  end
31
39
  end
32
40
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsEventOwner
2
- VERSION = "1.0.0" unless defined? ActsAsEventOwner::VERSION
2
+ VERSION = "1.1.0" unless defined? ActsAsEventOwner::VERSION
3
3
  end
@@ -7,32 +7,32 @@ describe ActsAsEventOwner::Core do
7
7
  @now = Time.now.utc
8
8
  @bod = Date.today.to_time.utc
9
9
  end
10
-
10
+
11
11
  it "adds associations to the host object" do
12
12
  lambda {
13
13
  @user.events
14
14
  @user.event_specifications
15
15
  }.should_not raise_error
16
16
  end
17
-
17
+
18
18
  it "adds event specifications to the host object" do
19
19
  lambda {
20
20
  @user.event_specifications.create :description => 'walk the dog', :start_at => @now, :repeat => :daily, :frequency => 1
21
21
  }.should change(EventSpecification, :count).by(1)
22
-
22
+
23
23
  specs = @user.reload.event_specifications
24
24
  specs.size.should == 1
25
25
  end
26
-
26
+
27
27
  it "adds events to the host object" do
28
28
  @user.event_specifications.create :description => 'walk the dog', :start_at => @now, :repeat => :daily, :frequency => 1, :generate => false
29
29
  @user.event_specifications.create :description => 'go to the gym', :start_at => @now, :repeat => :daily, :frequency => 2, :generate => false
30
-
30
+
31
31
  lambda {
32
32
  @user.events.generate :from => @bod, :to => @bod + 1.week
33
33
  }.should change(EventOccurrence, :count).by(11)
34
34
  end
35
-
35
+
36
36
  it "injects events into the association immediately" do
37
37
  @user.event_specifications.create :description => 'walk the dog', :start_at => @now, :repeat => :daily, :frequency => 1, :generate => false
38
38
  @user.events.should be_empty
@@ -40,7 +40,7 @@ describe ActsAsEventOwner::Core do
40
40
  @user.events.should be_present
41
41
  @user.events.size.should == 7
42
42
  end
43
-
43
+
44
44
  describe "events association" do
45
45
  before(:each) do
46
46
  @new_event = EventOccurrence.new
@@ -58,5 +58,20 @@ describe ActsAsEventOwner::Core do
58
58
  it "raises an exception if #create is called" do
59
59
  lambda { @user.events.create @new_event.attributes }.should raise_error(ActsAsEventOwner::Exception)
60
60
  end
61
+
62
+ describe "extensions" do
63
+ before(:each) do
64
+ @user.event_specifications.create :description => 'walk the dog', :start_at => @bod - 7.days, :repeat => :daily, :frequency => 1
65
+ @user.events.length.should == 30
66
+ end
67
+
68
+ it "provides an extension for upcoming events" do
69
+ @user.events.upcoming.length.should == 22
70
+ end
71
+
72
+ it "provides an extension for past events" do
73
+ @user.events.past.length.should == 8
74
+ end
75
+ end
61
76
  end
62
77
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
+ - 1
7
8
  - 0
8
- - 0
9
- version: 1.0.0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Danny Burkes
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-17 00:00:00 -07:00
17
+ date: 2010-11-27 00:00:00 -08:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency