ice_cube_model 0.0.2 → 0.0.3

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: 1128479e22af71166bf026bf19398f9f26de440f
4
- data.tar.gz: dbb48be74fe828c79b005855278c7699e83f534f
3
+ metadata.gz: b96485ea1cc05ea45c25c4a59d311a583697ca09
4
+ data.tar.gz: 4874513770391540298d29be1dfe90c24dd526fc
5
5
  SHA512:
6
- metadata.gz: ceec5f3cba596bf356dd19ce106dbd1910e24d53f1a78cb400b28160d7c680d3df28c1fae2eb32621054a282d51b97620dae13d3479832c5c2654a521ac06237
7
- data.tar.gz: 865e4a6b94862468c5075803c120d928ef990cb8569fb676ecf2dbef7a0ecac836ad95c9f33da8ba5709e2cacb57a2d08d3c85089d75325f0467953ecbf01528
6
+ metadata.gz: 5d1cc3024fff992cc68a3e93f421621de8b0db0224c65e38a36a2e708565472df3745d9f082ab05b2083f9783d33dfbb6d1375ea5e1ba3cacbe1f3585fddf1ca
7
+ data.tar.gz: 4f916dc2e3dc2d28984cc5c7e8849a32c58462ca3f2f73f962996c3257562ca6afcdcf41ebac2252a7f35dbede46670a4071b3349cc9f3a265e7b2662dc3882a
data/.gitignore CHANGED
@@ -35,3 +35,5 @@ Gemfile.lock
35
35
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
36
  .rvmrc
37
37
  Guardfile
38
+ vendor/cache
39
+ vendor/cache
data/README.md CHANGED
@@ -1,4 +1,7 @@
1
+ [![Gem Version](https://badge.fury.io/rb/ice_cube_model.svg)](https://badge.fury.io/rb/ice_cube_model)
2
+
1
3
  # ice_cube_model
4
+
2
5
  Extend any "cron-expression" object with [ice_cube](https://github.com/seejohnrun/ice_cube) (calendar repeating event) capabilities.
3
6
 
4
7
  Add ice_cube methods to a class (e.g. active_record, active_model) that has cron expression fields.
@@ -49,7 +52,6 @@ appointment.occurrences_between(::Date.new(2015, 3, 5), ::Date.new(2015, 6, 5))
49
52
  If needed, you can remap the attributes expected by ice_cube to other attributes or methods on the class.
50
53
 
51
54
  ```ruby
52
-
53
55
  # map to another attribute
54
56
  class Appointment
55
57
  attr_accessor
@@ -115,11 +117,9 @@ end
115
117
  - This gem is a work-in-progress.
116
118
  - `occurrences_between` is the only method currently supported.
117
119
  - Does not yet support all recurrence options. More coming.
118
- - Does not support inheritance. with_repeat_params called on child classes will mess with parent class' mappings.
120
+ - Supports inheritance but will not pick up dynamic changes in parent class parameter mappings.
119
121
 
120
122
  ## todo
121
- - Add support for repeat_end_date
122
- - Add support for inheritance
123
- - Add support for time
123
+ - Add support for time options
124
124
  - Allow mapping of a single cron expression (string) field, rather than individual fields.
125
125
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  ##
19
19
  # Dependencies
20
20
  #
21
- s.add_dependency 'ice_cube_cron', '>= 0.0.2'
21
+ s.add_dependency 'ice_cube_cron', '>= 0.0.3'
22
22
 
23
23
  ##
24
24
  # Development Dependencies
@@ -12,10 +12,18 @@ module IceCubeModel
12
12
  end
13
13
  alias_method :occurrences_between, :events_between
14
14
 
15
+ def respond_to?(name, include_private = false)
16
+ return true if self.class.repeat_parameter_mappings.values.include?(name.to_sym)
17
+ super
18
+ end
19
+
15
20
  private
16
21
 
17
22
  def read_repeat_parameter(param_name)
18
- send(self.class.repeat_parameter_mappings[param_name])
23
+ param_method = self.class.repeat_parameter_mappings[param_name.to_sym] || param_name.to_sym
24
+ return nil unless respond_to?(param_method)
25
+
26
+ send(param_method)
19
27
  end
20
28
 
21
29
  def read_repeat_params
@@ -24,34 +32,30 @@ module IceCubeModel
24
32
  :repeat_year => read_repeat_parameter(:repeat_year),
25
33
  :repeat_month => read_repeat_parameter(:repeat_month),
26
34
  :repeat_day => read_repeat_parameter(:repeat_day),
27
- :repeat_weekday => read_repeat_parameter(:repeat_weekday)
35
+ :repeat_weekday => read_repeat_parameter(:repeat_weekday),
36
+ :repeat_until => read_repeat_parameter(:repeat_until)
28
37
  }
29
38
  end
30
39
 
31
40
  module ClassMethods
32
41
  def repeat_parameter_mappings
33
- mappings_name = :@@repeat_parameter_mappings
34
-
35
- unless class_variable_defined?(mappings_name)
36
- class_variable_set(mappings_name, :repeat_start_date => :repeat_start_date,
37
- :repeat_interval => :repeat_interval,
38
- :repeat_year => :repeat_year,
39
- :repeat_month => :repeat_month,
40
- :repeat_day => :repeat_day,
41
- :repeat_weekday => :repeat_weekday)
42
+ @repeat_parameter_mappings ||= begin
43
+ if superclass.respond_to?(:repeat_parameter_mappings)
44
+ superclass.repeat_parameter_mappings.dup
45
+ else
46
+ {}
47
+ end
42
48
  end
43
-
44
- class_variable_get(mappings_name)
45
49
  end
46
50
 
47
51
  def with_repeat_param(param_name, replacement)
48
- repeat_parameter_mappings[param_name] = method_name = "repeat #{param_name}"
52
+ repeat_parameter_mappings[param_name] = param_sym = "ice_cube_model #{param_name}".to_sym
49
53
  if replacement.is_a?(::Proc)
50
- define_method(method_name) do
54
+ define_method(param_sym) do
51
55
  replacement.call
52
56
  end
53
57
  else
54
- define_method(method_name) do
58
+ define_method(param_sym) do
55
59
  send(replacement)
56
60
  end
57
61
  end
@@ -1,3 +1,3 @@
1
1
  module IceCubeModel
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -10,7 +10,8 @@ describe ::IceCubeModel do
10
10
  :repeat_month => nil,
11
11
  :repeat_day => nil,
12
12
  :repeat_weekday => nil,
13
- :repeat_week => nil
13
+ :repeat_week => nil,
14
+ :repeat_until => nil
14
15
  }.merge(attributes)
15
16
  end
16
17
 
@@ -24,6 +25,10 @@ describe ::IceCubeModel do
24
25
 
25
26
  fail ArgumentError, "Method `#{m}` doesn't exist."
26
27
  end
28
+
29
+ def respond_to?(name, _include_private = false)
30
+ @attributes.key?(name)
31
+ end
27
32
  end
28
33
 
29
34
  class IceCubeObj < HashAttrs
@@ -254,6 +259,20 @@ describe ::IceCubeModel do
254
259
  end
255
260
  end
256
261
 
262
+ context 'every month until date' do
263
+ let(:ice_cube_model) do
264
+ ::IceCubeObj.new(
265
+ :repeat_start_date => ::Date.new(2015, 1, 1),
266
+ :repeat_day => '1',
267
+ :repeat_until => ::Date.new(2015, 3, 1)
268
+ )
269
+ end
270
+
271
+ it 'ends on specified end date' do
272
+ 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)])
273
+ end
274
+ end
275
+
257
276
  context 'input types' do
258
277
  let(:ice_cube_model) do
259
278
  ::IceCubeObj.new(
@@ -290,7 +309,7 @@ describe ::IceCubeModel do
290
309
 
291
310
  with_repeat_param(:repeat_start_date, :start_date) # remap attribute to another
292
311
  with_repeat_param(:repeat_interval, :interval) # remap attribute to a method
293
- with_repeat_param(:repeat_day, -> { 1 }) # map parameter to lambda
312
+ with_repeat_param(:repeat_day, -> { 5 }) # map parameter to lambda
294
313
 
295
314
  def initialize(options = {})
296
315
  super(
@@ -313,35 +332,62 @@ describe ::IceCubeModel do
313
332
  end
314
333
 
315
334
  it 'should use class mappings' do
316
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 2, 1)])
335
+ expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 2, 5)])
317
336
  end
318
337
 
319
- class IceCubeObjWithParameterMappingsChild < IceCubeObjWithParameterMappings
320
- # Adding these currently mess up parent class mappings
321
- # with_repeat_param(:repeat_start_date, :starting) # remap attribute to another
322
- # with_repeat_param(:repeat_interval, :interval) # remap attribute to a method
338
+ context 'with inheritance' do
339
+ class IceCubeObjWithParameterMappingsChild < IceCubeObjWithParameterMappings
340
+ with_repeat_param(:repeat_start_date, :starting) # remap attribute to another
341
+ with_repeat_param(:repeat_interval, :interval) # remap attribute to a method
342
+ # with_repeat_param(:repeat_day, -> { 5 }) # comes from parent ::IceCubeObjWithParameterMappings
343
+
344
+ def initialize(options = {})
345
+ super(
346
+ {
347
+ :starting => nil
348
+ }.merge(options)
349
+ )
350
+ end
351
+
352
+ def interval
353
+ 2
354
+ end
355
+ end
323
356
 
324
- def initialize(options = {})
325
- super(
326
- {
327
- :starting => nil
328
- }.merge(options)
357
+ let(:ice_cube_model) do
358
+ ::IceCubeObjWithParameterMappingsChild.new(
359
+ :starting => ::Date.new(2015, 1, 1)
329
360
  )
330
361
  end
331
362
 
332
- def interval
333
- 2
363
+ it 'should inherit mappings and remap new mappings' do
364
+ 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)])
334
365
  end
335
366
  end
336
367
 
337
- it 'should support inheritance' do
338
- ice_cube_model = ::IceCubeObjWithParameterMappingsChild.new(
339
- :starting => ::Date.new(2015, 1, 1),
340
- :repeat_day => 2
341
- )
368
+ context 'with missing parameters' do
369
+ class IceCubeObjWithMissingParameters
370
+ include ::IceCubeModel::Base
342
371
 
343
- skip 'Not supported yet'
344
- expect(ice_cube_model.events_between(::Date.new(2015, 1, 1), ::Date.new(2015, 4, 30))).to eq([::Date.new(2015, 1, 2), ::Date.new(2015, 3, 2)])
372
+ attr_accessor :repeat_start_date
373
+ attr_accessor :repeat_day
374
+ end
375
+
376
+ it 'should work when class missing parameters' do
377
+ ice_cube_model = ::IceCubeObjWithMissingParameters.new
378
+
379
+ ice_cube_model.repeat_start_date = ::Date.new(2015, 1, 1)
380
+ ice_cube_model.repeat_day = 2
381
+
382
+ 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)])
383
+ end
384
+
385
+ it '#respond_to?' do
386
+ ice_cube_model = ::IceCubeObjWithMissingParameters.new
387
+ expect(ice_cube_model.respond_to?(:repeat_day)).to be(true)
388
+ expect(ice_cube_model.respond_to?(:repeat_interval)).to be(false)
389
+ expect(ice_cube_model.respond_to?(:methods)).to be(true)
390
+ end
345
391
  end
346
392
  end
347
393
  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.2
4
+ version: 0.0.3
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-15 00:00:00.000000000 Z
11
+ date: 2015-10-27 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.2
19
+ version: 0.0.3
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.2
26
+ version: 0.0.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement