ice_cube_model 0.0.4 → 1.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: edf86a2a7d7d80588e3965e382facda1e36284f5
4
- data.tar.gz: 567a5ff73291f7ef031072d47b95f0d1303fd096
3
+ metadata.gz: bcfcf6653953d60c0d1d4f421c25f7df4a743ba9
4
+ data.tar.gz: e4a733da032f4a22d1614fb5de13437dd3272fa5
5
5
  SHA512:
6
- metadata.gz: bbd4dc7514a93379baf57c39891eded3f3eb7f27d8b93faeaa998794117f86cc0d57b0d6566c0a5d2a8f557471e0c0062e13f57ef6c7036ce86a22c31c4b21c4
7
- data.tar.gz: 290d0270530a2467df0c4c2ecafde88d3ed4763e818a62709f909afd551941ff1bcf376ca9a1cbe73a3a05b5b0fe13798b485453381ebc6db7121a15d3c66a27
6
+ metadata.gz: 193bcaa3deb4eaeb58a3aa926177c6fe12f2e7dc3109adf3e2ed2b0ca755075b8b9839e60d784849e66bec7bb1baf6e041c65c6f616decab4480870b55816c51
7
+ data.tar.gz: d701384517b7ca81747f17dd3b1617b633bf608824aebe38806296242a6a480f5c4ad2c630bad590111ff9cdb9fadf82d28bb53718d1dcf3b345beb4ab351b1a
data/README.md CHANGED
@@ -119,6 +119,5 @@ end
119
119
  - Supports inheritance but will not pick up dynamic changes in parent class parameter mappings.
120
120
 
121
121
  ## todo
122
- - Add support for time options
123
122
  - Allow mapping of a single cron expression (string) field, rather than individual fields.
124
123
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  ##
19
19
  # Dependencies
20
20
  #
21
- s.add_runtime_dependency 'ice_cube_cron', '~> 0.0'
21
+ s.add_runtime_dependency 'ice_cube_cron', '~> 1'
22
22
 
23
23
  ##
24
24
  # Development Dependencies
@@ -7,3 +7,4 @@ require 'active_support/core_ext/integer'
7
7
  require 'ice_cube_model/version'
8
8
  require 'ice_cube_model/util'
9
9
  require 'ice_cube_model/base'
10
+ require 'ice_cube_model/delegator'
@@ -1,23 +1,5 @@
1
1
  module IceCubeModel
2
2
  module Base
3
- DELEGATED_METHODS = [
4
- :occurrences,
5
- :all_occurrences,
6
- :all_occurrences_enumerator,
7
- :next_occurrences,
8
- :next_occurrence,
9
- :previous_occurrences,
10
- :previous_occurrence,
11
- :remaining_occurrences,
12
- :remaining_occurrences_enumerator,
13
- :occurrences_between,
14
- :occurs_between?,
15
- :occurring_between?,
16
- :occurs_on?,
17
- :first,
18
- :last
19
- ]
20
-
21
3
  def self.included(base)
22
4
  base.extend(::IceCubeModel::Base::ClassMethods)
23
5
  end
@@ -26,32 +8,6 @@ module IceCubeModel
26
8
  ::IceCube::Schedule.from_cron(read_repeat_parameter(:repeat_start_date), read_repeat_params)
27
9
  end
28
10
 
29
- def respond_to?(name, include_private = false)
30
- ## Does respond to delegated methods. method_missing will lazy define them as they are used.
31
- return true if DELEGATED_METHODS.include?(name.to_sym)
32
- return true if self.class.repeat_parameter_mappings.values.include?(name.to_sym)
33
- super
34
- end
35
-
36
- # TODO: For backward compatibility. Remove before prod ready release.
37
- delegate :occurrences_between, :to => :schedule
38
- alias_method :events_between, :occurrences_between
39
-
40
- ##
41
- # Implementing method_missing as a *lazy* delegator. Doing this to prevent overwriting
42
- # target class' methods.
43
- #
44
- def method_missing(name, *args, &block)
45
- if DELEGATED_METHODS.include?(name.to_sym)
46
- self.class.send(:define_method, name.to_sym) do |*method_args|
47
- schedule.send(name, *method_args, &block)
48
- end
49
- send(name, *args)
50
- else
51
- super
52
- end
53
- end
54
-
55
11
  private
56
12
 
57
13
  def read_repeat_parameter(param_name)
@@ -66,8 +22,10 @@ module IceCubeModel
66
22
  :repeat_interval => read_repeat_parameter(:repeat_interval),
67
23
  :repeat_year => read_repeat_parameter(:repeat_year),
68
24
  :repeat_month => read_repeat_parameter(:repeat_month),
69
- :repeat_day => read_repeat_parameter(:repeat_day),
70
- :repeat_weekday => read_repeat_parameter(:repeat_weekday),
25
+ :repeat_day_of_month => read_repeat_parameter(:repeat_day_of_month),
26
+ :repeat_day_of_week => read_repeat_parameter(:repeat_day_of_week),
27
+ :repeat_hour => read_repeat_parameter(:repeat_hour),
28
+ :repeat_minute => read_repeat_parameter(:repeat_minute),
71
29
  :repeat_until => read_repeat_parameter(:repeat_until)
72
30
  }
73
31
  end
@@ -0,0 +1,27 @@
1
+ module IceCubeModel
2
+ module Delegator
3
+ DELEGATED_METHODS = [
4
+ :occurrences,
5
+ :all_occurrences,
6
+ :all_occurrences_enumerator,
7
+ :next_occurrences,
8
+ :next_occurrence,
9
+ :previous_occurrences,
10
+ :previous_occurrence,
11
+ :remaining_occurrences,
12
+ :remaining_occurrences_enumerator,
13
+ :occurrences_between,
14
+ :occurs_between?,
15
+ :occurring_between?,
16
+ :occurs_on?,
17
+ :first,
18
+ :last
19
+ ]
20
+
21
+ def self.included(_base)
22
+ DELEGATED_METHODS.each do |name|
23
+ delegate name, :to => :schedule
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module IceCubeModel
2
- VERSION = '0.0.4'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,38 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ::IceCubeModel do
4
- class HashAttrs
5
- def initialize(attributes = {})
6
- @attributes = {
7
- :repeat_start_date => nil,
8
- :repeat_interval => nil,
9
- :repeat_year => nil,
10
- :repeat_month => nil,
11
- :repeat_day => nil,
12
- :repeat_weekday => nil,
13
- :repeat_week => nil,
14
- :repeat_until => nil
15
- }.merge(attributes)
16
- end
17
-
18
- def method_missing(m, *args, &_block)
19
- if m =~ /[a-z_]+=/
20
- attribute = m.to_s.strip.chop.to_sym
21
- return @attributes[attribute] = args[0] if @attributes.key?(attribute)
22
- else
23
- return @attributes[m] if @attributes.key?(m)
24
- end
25
-
26
- fail ArgumentError, "Method `#{m}` doesn't exist."
27
- end
28
-
29
- def respond_to?(name, _include_private = false)
30
- return true if @attributes.key?(name)
31
-
32
- super
33
- end
34
- end
35
-
36
4
  class IceCubeObj < HashAttrs
37
5
  include ::IceCubeModel::Base
38
6
  end
@@ -43,264 +11,25 @@ describe ::IceCubeModel do
43
11
  )
44
12
  end
45
13
 
46
- context 'repeat options' do
47
- describe 'monthly' do
48
- before { ice_cube_model.repeat_day = '1' }
49
-
50
- it 'for same day' do
51
- expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 1))).to eq([::Date.new(2015, 7, 1)])
52
- end
53
-
54
- it 'for multiple months' do
55
- expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 9, 1))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 8, 1), ::Date.new(2015, 9, 1)])
56
- end
57
- end
58
-
59
- describe 'twice monthly' do
60
- before { ice_cube_model.repeat_day = '1,15' }
61
-
62
- it 'for one month' do
63
- expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 7, 15)])
64
- end
65
-
66
- it 'for two months' do
67
- expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 8, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 7, 15), ::Date.new(2015, 8, 1), ::Date.new(2015, 8, 15)])
68
- end
69
- end
70
-
71
- describe 'bi-monthly' do
72
- let(:ice_cube_model) do
73
- ::IceCubeObj.new(
74
- :repeat_start_date => ::Date.new(2015, 5, 1),
75
- :repeat_day => '1',
76
- :repeat_interval => '2'
77
- )
78
- end
79
-
80
- it 'for one month' do
81
- expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
82
- end
83
-
84
- it 'for multiple months' do
85
- expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 10, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 9, 1)])
86
- end
87
- end
88
-
89
- describe 'every week' do
90
- let(:ice_cube_model) do
91
- ::IceCubeObj.new(
92
- :repeat_start_date => ::Date.new(2015, 7, 6),
93
- :repeat_weekday => '1',
94
- :repeat_day => nil
95
- )
96
- end
97
-
98
- it 'for one week' do
99
- expect(
100
- ice_cube_model.events_between(
101
- ::Date.new(2015, 7, 1),
102
- ::Date.new(2015, 7, 7)
103
- )
104
- ).to eq([::Date.new(2015, 7, 6)])
105
- end
106
-
107
- it 'for one month' do
108
- expect(
109
- ice_cube_model.events_between(
110
- ::Date.new(2015, 7, 1),
111
- ::Date.new(2015, 8, 31)
112
- )
113
- ).to eq(
114
- [
115
- ::Date.new(2015, 7, 6),
116
- ::Date.new(2015, 7, 13),
117
- ::Date.new(2015, 7, 20),
118
- ::Date.new(2015, 7, 27),
119
- ::Date.new(2015, 8, 3),
120
- ::Date.new(2015, 8, 10),
121
- ::Date.new(2015, 8, 17),
122
- ::Date.new(2015, 8, 24),
123
- ::Date.new(2015, 8, 31)
124
- ]
125
- )
126
- end
127
- end
128
-
129
- describe 'bi-weekly' do
130
- let(:ice_cube_model) do
131
- ::IceCubeObj.new(
132
- :repeat_start_date => ::Date.new(2015, 7, 6),
133
- :repeat_weekday => '1',
134
- :repeat_day => nil,
135
- :repeat_interval => '2'
136
- )
137
- end
138
-
139
- it 'for one week' do
140
- expect(
141
- ice_cube_model.events_between(
142
- ::Date.new(2015, 7, 1),
143
- ::Date.new(2015, 7, 7)
144
- )
145
- ).to eq([::Date.new(2015, 7, 6)])
146
- end
147
-
148
- it 'for two months' do
149
- expect(
150
- ice_cube_model.events_between(
151
- ::Date.new(2015, 7, 1),
152
- ::Date.new(2015, 8, 31)
153
- )
154
- ).to eq(
155
- [
156
- ::Date.new(2015, 7, 6),
157
- # ::Date.new(2015, 7, 13),
158
- ::Date.new(2015, 7, 20),
159
- # ::Date.new(2015, 7, 27),
160
- ::Date.new(2015, 8, 3),
161
- # ::Date.new(2015, 8, 10),
162
- ::Date.new(2015, 8, 17),
163
- # ::Date.new(2015, 8, 24),
164
- ::Date.new(2015, 8, 31)
165
- ]
166
- )
167
- end
168
- end
169
-
170
- describe 'annually' do
171
- let(:ice_cube_model) do
172
- ::IceCubeObj.new(
173
- :repeat_start_date => ::Date.new(2015, 1, 1),
174
- :repeat_month => 2,
175
- :repeat_day => 1
176
- )
177
- end
178
-
179
- it 'for one year' do
180
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 2, 1)])
181
- end
182
-
183
- it 'for two years' do
184
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2016, 12, 31))).to eq([::Date.new(2015, 2, 1), ::Date.new(2016, 2, 1)])
185
- end
186
- end
187
-
188
- describe 'bi-annually' do
189
- let(:ice_cube_model) do
190
- ::IceCubeObj.new(
191
- :repeat_start_date => ::Date.new(2015, 1, 1),
192
- :repeat_interval => 2,
193
- :repeat_month => 2,
194
- :repeat_day => 1
195
- )
196
- end
197
-
198
- it 'for two years' do
199
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2016, 12, 31))).to eq([::Date.new(2015, 2, 1)])
200
- end
201
- end
202
-
203
- describe 'last weekday of month' do
204
- context '31 day month' do
205
- let(:ice_cube_model) do
206
- ::IceCubeObj.new(
207
- :repeat_start_date => ::Date.new(2015, 1, 1),
208
- :repeat_weekday => '5L'
209
- )
210
- end
211
-
212
- it 'for one month' do
213
- expect(ice_cube_model.events_between(::Date.new(2015, 12, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 12, 25)])
214
- end
215
- end
216
-
217
- context '29 day month' do
218
- let(:ice_cube_model) do
219
- ::IceCubeObj.new(
220
- :repeat_start_date => ::Date.new(2015, 1, 1),
221
- :repeat_weekday => '3L'
222
- )
223
- end
224
-
225
- it 'for one month' do
226
- expect(ice_cube_model.events_between(::Date.new(2016, 2, 1), ::Date.new(2016, 2, 29))).to eq([::Date.new(2016, 2, 24)])
227
- end
228
- end
229
- end
230
-
231
- describe 'last day of month' do
232
- context '31 day month' do
233
- let(:ice_cube_model) do
234
- ::IceCubeObj.new(
235
- :repeat_start_date => ::Date.new(2015, 1, 1),
236
- :repeat_day => 'L'
237
- )
238
- end
239
-
240
- it 'for one multiple months' do
241
- expect(ice_cube_model.events_between(::Date.new(2015, 12, 1), ::Date.new(2016, 3, 1))).to eq([::Date.new(2015, 12, 31), ::Date.new(2016, 1, 31), ::Date.new(2016, 2, 29)])
242
- end
243
- end
244
- end
245
-
246
- describe 'Nth day of week of month' do
247
- let(:ice_cube_model) do
248
- ::IceCubeObj.new(
249
- :repeat_start_date => ::Date.new(2015, 1, 1),
250
- :repeat_weekday => '1#2'
251
- )
252
- end
253
-
254
- it 'for one month' do
255
- expect(ice_cube_model.events_between(::Date.new(2016, 2, 1), ::Date.new(2016, 2, 29))).to eq([::Date.new(2016, 2, 8)])
256
- end
257
-
258
- it 'for mutiple months' do
259
- expect(ice_cube_model.events_between(::Date.new(2016, 2, 1), ::Date.new(2016, 4, 30))).to eq([::Date.new(2016, 2, 8), ::Date.new(2016, 3, 14), ::Date.new(2016, 4, 11)])
260
- end
261
- end
262
- end
263
-
264
- context 'every month until date' do
265
- let(:ice_cube_model) do
266
- ::IceCubeObj.new(
267
- :repeat_start_date => ::Date.new(2015, 1, 1),
268
- :repeat_day => '1',
269
- :repeat_until => ::Date.new(2015, 3, 1)
270
- )
271
- end
272
-
273
- it 'ends on specified end date' do
274
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2015, 6, 30))).to eq([::Date.new(2015, 1, 1), ::Date.new(2015, 2, 1), ::Date.new(2015, 3, 1)])
275
- end
276
- end
277
-
278
- context 'input types' do
279
- let(:ice_cube_model) do
280
- ::IceCubeObj.new(
281
- :repeat_start_date => ::DateTime.new(2015, 5, 1),
282
- :repeat_day => '1',
283
- :repeat_interval => '2'
284
- )
285
- end
286
-
287
- it 'handles ::DateTime as input' do
288
- expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
289
- end
290
-
291
- it 'handles integer (epoch) as input' do
292
- ice_cube_model.repeat_start_date = 1_430_438_400 # Fri, 01 May 2015 00:00:00 GMT
293
- expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::DateTime.new(2015, 7, 1)])
294
- end
295
- end
296
-
297
- context '::IceCubeModel::Base' do
298
- describe '#events_between' do
299
- it 'should emit [::Time]' do
300
- results = ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))
301
- expect(results).to eq([::Date.new(2015, 7, 1)])
302
- expect(results[0]).to be_a(::Time)
303
- end
14
+ describe '.schedule' do
15
+ it 'assigns all information' do
16
+ ice_cube_model.repeat_interval = 1
17
+ ice_cube_model.repeat_year = 2015
18
+ ice_cube_model.repeat_month = 2
19
+ ice_cube_model.repeat_day_of_month = 3
20
+ ice_cube_model.repeat_day_of_week = 4
21
+ ice_cube_model.repeat_hour = 5
22
+ ice_cube_model.repeat_minute = 6
23
+
24
+ validations = ice_cube_model.schedule.recurrence_rules.first.validations
25
+
26
+ expect(validations[:interval].first.interval).to eq(1)
27
+ expect(validations[:year].first.value).to eq(2015)
28
+ expect(validations[:month_of_year].first.value).to eq(2)
29
+ expect(validations[:day_of_month].first.value).to eq(3)
30
+ expect(validations[:day].first.value).to eq(4)
31
+ expect(validations[:hour_of_day].first.value).to eq(5)
32
+ expect(validations[:minute_of_hour].first.value).to eq(6)
304
33
  end
305
34
  end
306
35
 
@@ -308,10 +37,11 @@ describe ::IceCubeModel do
308
37
  describe '#with_repeat_param' do
309
38
  class IceCubeObjWithParameterMappings < HashAttrs
310
39
  include ::IceCubeModel::Base
40
+ include ::IceCubeModel::Delegator
311
41
 
312
42
  with_repeat_param(:repeat_start_date, :start_date) # remap attribute to another
313
43
  with_repeat_param(:repeat_interval, :interval) # remap attribute to a method
314
- with_repeat_param(:repeat_day, -> { 5 }) # map parameter to lambda
44
+ with_repeat_param(:repeat_day_of_month, -> { 5 }) # map parameter to lambda
315
45
 
316
46
  def initialize(options = {})
317
47
  super(
@@ -334,14 +64,14 @@ describe ::IceCubeModel do
334
64
  end
335
65
 
336
66
  it 'should use class mappings' do
337
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 2, 5)])
67
+ expect(ice_cube_model.schedule.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 2, 5)])
338
68
  end
339
69
 
340
70
  context 'with inheritance' do
341
71
  class IceCubeObjWithParameterMappingsChild < IceCubeObjWithParameterMappings
342
72
  with_repeat_param(:repeat_start_date, :starting) # remap attribute to another
343
73
  with_repeat_param(:repeat_interval, :interval) # remap attribute to a method
344
- # with_repeat_param(:repeat_day, -> { 5 }) # comes from parent ::IceCubeObjWithParameterMappings
74
+ # with_repeat_param(:repeat_day_of_month, -> { 5 }) # comes from parent ::IceCubeObjWithParameterMappings
345
75
 
346
76
  def initialize(options = {})
347
77
  super(
@@ -363,121 +93,38 @@ describe ::IceCubeModel do
363
93
  end
364
94
 
365
95
  it 'should inherit mappings and remap new mappings' do
366
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2015, 4, 30))).to eq([::Date.new(2015, 1, 5), ::Date.new(2015, 3, 5)])
96
+ expect(ice_cube_model.schedule.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2015, 4, 30))).to eq([::Date.new(2015, 1, 5), ::Date.new(2015, 3, 5)])
367
97
  end
368
98
  end
369
99
 
370
100
  context 'with missing parameters' do
371
101
  class IceCubeObjWithMissingParameters
372
102
  include ::IceCubeModel::Base
103
+ include ::IceCubeModel::Delegator
373
104
 
374
105
  attr_accessor :repeat_start_date
375
- attr_accessor :repeat_day
106
+ attr_accessor :repeat_day_of_month
107
+
108
+ with_repeat_param :repeat_hour, -> { 0 }
109
+ with_repeat_param :repeat_minute, -> { 0 }
376
110
  end
377
111
 
378
112
  it 'should work when class missing parameters' do
379
113
  ice_cube_model = ::IceCubeObjWithMissingParameters.new
380
114
 
381
115
  ice_cube_model.repeat_start_date = ::Date.new(2015, 1, 1)
382
- ice_cube_model.repeat_day = 2
116
+ ice_cube_model.repeat_day_of_month = 2
383
117
 
384
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2015, 2, 28))).to eq([::Date.new(2015, 1, 2), ::Date.new(2015, 2, 2)])
118
+ expect(ice_cube_model.schedule.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2015, 2, 28))).to eq([::Date.new(2015, 1, 2), ::Date.new(2015, 2, 2)])
385
119
  end
386
120
 
387
121
  it '#respond_to?' do
388
122
  ice_cube_model = ::IceCubeObjWithMissingParameters.new
389
- expect(ice_cube_model.respond_to?(:repeat_day)).to be(true)
123
+ expect(ice_cube_model.respond_to?(:repeat_day_of_month)).to be(true)
390
124
  expect(ice_cube_model.respond_to?(:repeat_interval)).to be(false)
391
125
  expect(ice_cube_model.respond_to?(:methods)).to be(true)
392
126
  end
393
127
  end
394
128
  end
395
129
  end
396
-
397
- describe 'delagated methods' do
398
- let(:ice_cube_model) do
399
- ::IceCubeObj.new(
400
- :repeat_start_date => ::Date.new(2015, 6, 1),
401
- :repeat_day => 5
402
- )
403
- end
404
-
405
- it '#occurrences' do
406
- expect(ice_cube_model.occurrences(::Date.new(2015, 8, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
407
- end
408
-
409
- it '#all_occurrences' do
410
- ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
411
- expect(ice_cube_model.all_occurrences).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
412
- end
413
-
414
- it '#all_occurrences_enumerator' do
415
- ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
416
- expect(ice_cube_model.all_occurrences_enumerator.map { |occurrence| occurrence }).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
417
- end
418
-
419
- it '#next_occurrences' do
420
- expect(ice_cube_model.next_occurrences(2, ::Date.new(2015, 6, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
421
- end
422
-
423
- it '#next_occurrence' do
424
- expect(ice_cube_model.next_occurrence(::Date.new(2015, 6, 1))).to eq(::Date.new(2015, 6, 5))
425
- end
426
-
427
- it '#previous_occurrences' do
428
- expect(ice_cube_model.previous_occurrences(2, ::Date.new(2015, 8, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
429
- end
430
-
431
- it '#previous_occurrence' do
432
- expect(ice_cube_model.previous_occurrence(::Date.new(2015, 8, 1))).to eq(::Date.new(2015, 7, 5))
433
- end
434
-
435
- it '#remaining_occurrences' do
436
- ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
437
- expect(ice_cube_model.remaining_occurrences(::Date.new(2015, 6, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
438
- end
439
-
440
- it '#remaining_occurrences_enumerator' do
441
- ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
442
- expect(ice_cube_model.remaining_occurrences_enumerator(::Date.new(2015, 6, 1)).map { |occurrence| occurrence }).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
443
- end
444
-
445
- it '#occurrences_between' do
446
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 6, 1), ::Date.new(2015, 8, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
447
- expect(ice_cube_model.events_between(::Date.new(2015, 6, 1), ::Date.new(2015, 8, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
448
- end
449
-
450
- it '#occurs_between?' do
451
- expect(ice_cube_model.occurs_between?(::Date.new(2015, 7, 1), ::Date.new(2015, 8, 1))).to be(true)
452
- end
453
-
454
- it '#occurring_between?' do
455
- expect(ice_cube_model.occurring_between?(::Date.new(2015, 6, 1), ::Date.new(2015, 8, 1))).to be(true)
456
- end
457
-
458
- it '#occurs_on?' do
459
- expect(ice_cube_model.occurs_on?(::Date.new(2015, 6, 5))).to be(true)
460
- end
461
-
462
- it '#occurring_at?' do
463
- skip 'Time options not implemented yet'
464
- end
465
-
466
- it '#conflicts_with?' do
467
- skip 'Time options not implemented yet'
468
- end
469
-
470
- it '#occurs_at?' do
471
- skip 'Time options not implemented yet'
472
- end
473
-
474
- it '#first' do
475
- expect(ice_cube_model.first(2)).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
476
- end
477
-
478
- it '#last' do
479
- ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
480
- expect(ice_cube_model.last(2)).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
481
- end
482
- end
483
130
  end
@@ -0,0 +1,94 @@
1
+ require 'spec_helper'
2
+
3
+ describe ::IceCubeModel::Delegator do
4
+ class IceCubeObjWithDelegates < HashAttrs
5
+ include ::IceCubeModel::Base
6
+ include ::IceCubeModel::Delegator
7
+ end
8
+
9
+ let(:ice_cube_model) do
10
+ ::IceCubeObjWithDelegates.new(
11
+ :repeat_start_date => ::Date.new(2015, 6, 1),
12
+ :repeat_day_of_month => 5,
13
+ :repeat_hour => 0,
14
+ :repeat_minute => 0
15
+ )
16
+ end
17
+
18
+ it '#occurrences' do
19
+ expect(ice_cube_model.occurrences(::Date.new(2015, 8, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
20
+ end
21
+
22
+ it '#all_occurrences' do
23
+ ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
24
+ expect(ice_cube_model.all_occurrences).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
25
+ end
26
+
27
+ it '#all_occurrences_enumerator' do
28
+ ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
29
+ expect(ice_cube_model.all_occurrences_enumerator.map { |occurrence| occurrence }).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
30
+ end
31
+
32
+ it '#next_occurrences' do
33
+ expect(ice_cube_model.next_occurrences(2, ::Date.new(2015, 6, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
34
+ end
35
+
36
+ it '#next_occurrence' do
37
+ expect(ice_cube_model.next_occurrence(::Date.new(2015, 6, 1))).to eq(::Date.new(2015, 6, 5))
38
+ end
39
+
40
+ it '#previous_occurrences' do
41
+ expect(ice_cube_model.previous_occurrences(2, ::Date.new(2015, 8, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
42
+ end
43
+
44
+ it '#previous_occurrence' do
45
+ expect(ice_cube_model.previous_occurrence(::Date.new(2015, 8, 1))).to eq(::Date.new(2015, 7, 5))
46
+ end
47
+
48
+ it '#remaining_occurrences' do
49
+ ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
50
+ expect(ice_cube_model.remaining_occurrences(::Date.new(2015, 6, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
51
+ end
52
+
53
+ it '#remaining_occurrences_enumerator' do
54
+ ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
55
+ expect(ice_cube_model.remaining_occurrences_enumerator(::Date.new(2015, 6, 1)).map { |occurrence| occurrence }).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
56
+ end
57
+
58
+ it '#occurrences_between' do
59
+ expect(ice_cube_model.occurrences_between(::Date.new(2015, 6, 1), ::Date.new(2015, 8, 1))).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
60
+ end
61
+
62
+ it '#occurs_between?' do
63
+ expect(ice_cube_model.occurs_between?(::Date.new(2015, 7, 1), ::Date.new(2015, 8, 1))).to be(true)
64
+ end
65
+
66
+ it '#occurring_between?' do
67
+ expect(ice_cube_model.occurring_between?(::Date.new(2015, 6, 1), ::Date.new(2015, 8, 1))).to be(true)
68
+ end
69
+
70
+ it '#occurs_on?' do
71
+ expect(ice_cube_model.occurs_on?(::Date.new(2015, 6, 5))).to be(true)
72
+ end
73
+
74
+ it '#occurring_at?' do
75
+ skip 'Time options not implemented yet'
76
+ end
77
+
78
+ it '#conflicts_with?' do
79
+ skip 'Time options not implemented yet'
80
+ end
81
+
82
+ it '#occurs_at?' do
83
+ skip 'Time options not implemented yet'
84
+ end
85
+
86
+ it '#first' do
87
+ expect(ice_cube_model.first(2)).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
88
+ end
89
+
90
+ it '#last' do
91
+ ice_cube_model.repeat_until = ::Date.new(2015, 8, 1)
92
+ expect(ice_cube_model.last(2)).to eq([::Date.new(2015, 6, 5), ::Date.new(2015, 7, 5)])
93
+ end
94
+ end
data/spec/spec_helper.rb CHANGED
@@ -44,3 +44,5 @@ RSpec.configure do |config|
44
44
  mocks.verify_partial_doubles = true
45
45
  end
46
46
  end
47
+
48
+ Dir[File.dirname(__FILE__) + '/support/**/*.rb'].each { |f| require f }
@@ -0,0 +1,33 @@
1
+ class HashAttrs
2
+ def initialize(attributes = {})
3
+ @attributes = {
4
+ :repeat_start_date => nil,
5
+ :repeat_interval => nil,
6
+ :repeat_year => nil,
7
+ :repeat_month => nil,
8
+ :repeat_day_of_month => nil,
9
+ :repeat_day_of_week => nil,
10
+ :repeat_week => nil,
11
+ :repeat_hour => 0,
12
+ :repeat_minute => 0,
13
+ :repeat_until => nil
14
+ }.merge(attributes)
15
+ end
16
+
17
+ def method_missing(m, *args, &_block)
18
+ if m =~ /[a-z_]+=/
19
+ attribute = m.to_s.strip.chop.to_sym
20
+ return @attributes[attribute] = args[0] if @attributes.key?(attribute)
21
+ else
22
+ return @attributes[m] if @attributes.key?(m)
23
+ end
24
+
25
+ fail ArgumentError, "Method `#{m}` doesn't exist."
26
+ end
27
+
28
+ def respond_to?(name, _include_private = false)
29
+ return true if @attributes.key?(name)
30
+
31
+ super
32
+ end
33
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Nichols
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-28 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ice_cube_cron
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.0'
19
+ version: '1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.0'
26
+ version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -96,11 +96,14 @@ files:
96
96
  - ice_cube_model.gemspec
97
97
  - lib/ice_cube_model.rb
98
98
  - lib/ice_cube_model/base.rb
99
+ - lib/ice_cube_model/delegator.rb
99
100
  - lib/ice_cube_model/util.rb
100
101
  - lib/ice_cube_model/version.rb
101
102
  - spec/lib/ice_cube_model/base_spec.rb
103
+ - spec/lib/ice_cube_model/delegator_spec.rb
102
104
  - spec/lib/ice_cube_model/util_spec.rb
103
105
  - spec/spec_helper.rb
106
+ - spec/support/hash_attrs.rb
104
107
  homepage: https://github.com/mattnichols/ice_cube_model
105
108
  licenses:
106
109
  - MIT
@@ -127,5 +130,7 @@ specification_version: 4
127
130
  summary: Extend any class with ice_cube (calendar repeating events) capabilities.
128
131
  test_files:
129
132
  - spec/lib/ice_cube_model/base_spec.rb
133
+ - spec/lib/ice_cube_model/delegator_spec.rb
130
134
  - spec/lib/ice_cube_model/util_spec.rb
131
135
  - spec/spec_helper.rb
136
+ - spec/support/hash_attrs.rb