ice_cube_model 0.0.3 → 0.0.4

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: b96485ea1cc05ea45c25c4a59d311a583697ca09
4
- data.tar.gz: 4874513770391540298d29be1dfe90c24dd526fc
3
+ metadata.gz: edf86a2a7d7d80588e3965e382facda1e36284f5
4
+ data.tar.gz: 567a5ff73291f7ef031072d47b95f0d1303fd096
5
5
  SHA512:
6
- metadata.gz: 5d1cc3024fff992cc68a3e93f421621de8b0db0224c65e38a36a2e708565472df3745d9f082ab05b2083f9783d33dfbb6d1375ea5e1ba3cacbe1f3585fddf1ca
7
- data.tar.gz: 4f916dc2e3dc2d28984cc5c7e8849a32c58462ca3f2f73f962996c3257562ca6afcdcf41ebac2252a7f35dbede46670a4071b3349cc9f3a265e7b2662dc3882a
6
+ metadata.gz: bbd4dc7514a93379baf57c39891eded3f3eb7f27d8b93faeaa998794117f86cc0d57b0d6566c0a5d2a8f557471e0c0062e13f57ef6c7036ce86a22c31c4b21c4
7
+ data.tar.gz: 290d0270530a2467df0c4c2ecafde88d3ed4763e818a62709f909afd551941ff1bcf376ca9a1cbe73a3a05b5b0fe13798b485453381ebc6db7121a15d3c66a27
data/Gemfile.lock CHANGED
@@ -2,7 +2,7 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  ice_cube_model (0.0.3)
5
- ice_cube_cron (>= 0.0.3)
5
+ ice_cube_cron (~> 0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
@@ -20,16 +20,16 @@ GEM
20
20
  diff-lcs (1.2.5)
21
21
  i18n (0.7.0)
22
22
  ice_cube (0.13.0)
23
- ice_cube_cron (0.0.3)
24
- activesupport (>= 3.0.0)
25
- ice_cube (= 0.13.0)
23
+ ice_cube_cron (0.0.4)
24
+ activesupport (~> 4)
25
+ ice_cube (~> 0.13)
26
26
  json (1.8.3)
27
27
  method_source (0.8.2)
28
28
  minitest (5.8.2)
29
29
  parser (2.2.3.0)
30
30
  ast (>= 1.1, < 3.0)
31
31
  powerpack (0.1.1)
32
- pry (0.10.2)
32
+ pry (0.10.3)
33
33
  coderay (~> 1.1.0)
34
34
  method_source (~> 0.8.1)
35
35
  slop (~> 3.4)
@@ -65,10 +65,10 @@ PLATFORMS
65
65
 
66
66
  DEPENDENCIES
67
67
  ice_cube_model!
68
- pry
69
- rake
70
- rspec
71
- rubocop
68
+ pry (~> 0)
69
+ rake (~> 10)
70
+ rspec (~> 3.3)
71
+ rubocop (~> 0.34)
72
72
 
73
73
  BUNDLED WITH
74
74
  1.10.6
data/README.md CHANGED
@@ -115,7 +115,6 @@ end
115
115
 
116
116
  ## notes
117
117
  - This gem is a work-in-progress.
118
- - `occurrences_between` is the only method currently supported.
119
118
  - Does not yet support all recurrence options. More coming.
120
119
  - Supports inheritance but will not pick up dynamic changes in parent class parameter mappings.
121
120
 
@@ -3,14 +3,14 @@ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
3
3
  require 'ice_cube_model/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = 'ice_cube_model'
7
- s.version = IceCubeModel::VERSION
8
- s.authors = ['Matt Nichols']
9
- s.email = ['matt@nichols.name']
10
- s.homepage = 'https://github.com/mattnichols/ice_cube_model'
11
- s.summary = 'Extend any class with ice_cube (calendar repeating events) capabilities.'
12
- s.description = 'Add ice_cube methods to classes (e.g. active_record, active_model).'
13
-
6
+ s.name = 'ice_cube_model'
7
+ s.version = IceCubeModel::VERSION
8
+ s.authors = ['Matt Nichols']
9
+ s.email = ['matt@nichols.name']
10
+ s.homepage = 'https://github.com/mattnichols/ice_cube_model'
11
+ s.summary = 'Extend any class with ice_cube (calendar repeating events) capabilities.'
12
+ s.description = 'Add ice_cube methods to classes (e.g. active_record, active_model).'
13
+ s.license = 'MIT'
14
14
  s.files = `git ls-files`.split("\n")
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.require_paths = ['lib']
@@ -18,13 +18,13 @@ Gem::Specification.new do |s|
18
18
  ##
19
19
  # Dependencies
20
20
  #
21
- s.add_dependency 'ice_cube_cron', '>= 0.0.3'
21
+ s.add_runtime_dependency 'ice_cube_cron', '~> 0.0'
22
22
 
23
23
  ##
24
24
  # Development Dependencies
25
25
  #
26
- s.add_development_dependency 'rake'
27
- s.add_development_dependency 'pry'
28
- s.add_development_dependency 'rspec'
29
- s.add_development_dependency 'rubocop'
26
+ s.add_development_dependency 'rake', '~> 10'
27
+ s.add_development_dependency 'pry', '~> 0'
28
+ s.add_development_dependency 'rspec', '~> 3.3'
29
+ s.add_development_dependency 'rubocop', '~> 0.34'
30
30
  end
@@ -1,22 +1,57 @@
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
+
3
21
  def self.included(base)
4
22
  base.extend(::IceCubeModel::Base::ClassMethods)
5
23
  end
6
24
 
7
- def events_between(start, through)
8
- params = read_repeat_params
9
- schedule = ::IceCube::Schedule.from_cron(read_repeat_parameter(:repeat_start_date), params)
10
-
11
- schedule.occurrences_between(::IceCubeModel::Util.sanitize_date_param(start), ::IceCubeModel::Util.sanitize_date_param(through))
25
+ def schedule
26
+ ::IceCube::Schedule.from_cron(read_repeat_parameter(:repeat_start_date), read_repeat_params)
12
27
  end
13
- alias_method :occurrences_between, :events_between
14
28
 
15
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)
16
32
  return true if self.class.repeat_parameter_mappings.values.include?(name.to_sym)
17
33
  super
18
34
  end
19
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
+
20
55
  private
21
56
 
22
57
  def read_repeat_parameter(param_name)
@@ -1,3 +1,3 @@
1
1
  module IceCubeModel
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -27,7 +27,9 @@ describe ::IceCubeModel do
27
27
  end
28
28
 
29
29
  def respond_to?(name, _include_private = false)
30
- @attributes.key?(name)
30
+ return true if @attributes.key?(name)
31
+
32
+ super
31
33
  end
32
34
  end
33
35
 
@@ -283,12 +285,12 @@ describe ::IceCubeModel do
283
285
  end
284
286
 
285
287
  it 'handles ::DateTime as input' do
286
- expect(ice_cube_model.events_between(::DateTime.new(2015, 7, 1), ::DateTime.new(2015, 7, 31))).to eq([::DateTime.new(2015, 7, 1)])
288
+ expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
287
289
  end
288
290
 
289
291
  it 'handles integer (epoch) as input' do
290
292
  ice_cube_model.repeat_start_date = 1_430_438_400 # Fri, 01 May 2015 00:00:00 GMT
291
- expect(ice_cube_model.events_between(::DateTime.new(2015, 7, 1), ::DateTime.new(2015, 7, 31))).to eq([::DateTime.new(2015, 7, 1)])
293
+ expect(ice_cube_model.events_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::DateTime.new(2015, 7, 1)])
292
294
  end
293
295
  end
294
296
 
@@ -391,4 +393,91 @@ describe ::IceCubeModel do
391
393
  end
392
394
  end
393
395
  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
394
483
  end
metadata CHANGED
@@ -1,85 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
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-27 00:00:00.000000000 Z
11
+ date: 2015-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ice_cube_cron
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.3
19
+ version: '0.0'
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.3
26
+ version: '0.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '3.3'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '3.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '0.34'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '0.34'
83
83
  description: Add ice_cube methods to classes (e.g. active_record, active_model).
84
84
  email:
85
85
  - matt@nichols.name
@@ -102,7 +102,8 @@ files:
102
102
  - spec/lib/ice_cube_model/util_spec.rb
103
103
  - spec/spec_helper.rb
104
104
  homepage: https://github.com/mattnichols/ice_cube_model
105
- licenses: []
105
+ licenses:
106
+ - MIT
106
107
  metadata: {}
107
108
  post_install_message:
108
109
  rdoc_options: []