schedulable 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf160baa485b91e6566ffb4a3d4914058237f634
4
- data.tar.gz: edfc6d3c758cbdef642e633a1a32869f6a386327
3
+ metadata.gz: d5965f8d54d74a2e9dc9a3637bdac730fac29861
4
+ data.tar.gz: ee86cfa84c07e0ae273ae3d70e76f811cfb28a3f
5
5
  SHA512:
6
- metadata.gz: 555836580530752b1eecf9cf85cf9b8f7a44f5d12fb62254555930f895608d7a644a3f555a5c98e09b1fdb366466733952eea3afd31d053a4567406d074145c7
7
- data.tar.gz: a47bd73ac68eeff77a1dcecbcebab3d32c4e41a04fe429efe13d862d54397475f08f50f8a51ab3a2a8755e343c1d65090d031ed95b3904ca7593ec4fd98741a4
6
+ metadata.gz: f8cc72da05d83051a102e51fbc3a2ef5378e8f0d3529a1f715c7110820ccd361f28f2d7c638c5cb2b20b98e33db6adcd27f5f22ac621096905ee6ce79067486b
7
+ data.tar.gz: 49e83fe2ecaf68a9cbc12e361ec19c2c913447991c983d4e5afa0e57d12970bb327510a48f7ea84f3a3e87b2d21d002900dd84bfa87bfb134955bc1889ab82c9
@@ -64,8 +64,8 @@ class ScheduleInput < SimpleForm::Inputs::Base
64
64
  weekdays.reduce(''.html_safe) do | content, weekday |
65
65
  content << template.content_tag("div", nil, style: 'display: table-row') do
66
66
  template.content_tag("span", day_labels[weekday] || weekday, style: 'display: table-cell') <<
67
- db.collection_check_boxes(weekday.to_sym, [1, 2, 3, 4, -1], lambda { |i| i} , lambda { |i| "&nbsp;".html_safe}, checked: db.object.send(weekday), item_wrapper_tag: nil) do |cb|
68
- template.content_tag("span", cb.check_box(), style: 'display: table-cell; text-align: center')
67
+ db.collection_check_boxes(weekday.to_sym, [1, 2, 3, 4, -1], lambda { |i| i} , lambda { |i| "&nbsp;".html_safe}, boolean_style: :inline, label: false, checked: db.object.send(weekday), inline_label: false, item_wrapper_tag: nil) do |cb|
68
+ template.content_tag("span", style: 'display: table-cell; text-align: center;') { cb.check_box(class: "check_box") }
69
69
  end
70
70
  end
71
71
  end
@@ -62,10 +62,15 @@ module Schedulable
62
62
  end
63
63
  end
64
64
 
65
+ define_method "build_#{occurrences_association}_after_update" do
66
+ schedule = self.send(name)
67
+ if schedule.changes.any?
68
+ self.send("build_#{occurrences_association}")
69
+ end
70
+ end
71
+
65
72
  define_method "build_#{occurrences_association}" do
66
73
 
67
- puts 'build occurrences...'
68
-
69
74
  # build occurrences for events
70
75
 
71
76
  schedule = self.send(name)
@@ -87,9 +92,8 @@ module Schedulable
87
92
  max_count = terminating && schedule.remaining_occurrences.any? ? [max_count, schedule.remaining_occurrences.count].min : max_count
88
93
 
89
94
  if schedule.rule != 'singular'
90
-
91
95
  # Get schedule occurrences
92
- all_occurrences = schedule.occurrences(max_date)
96
+ all_occurrences = schedule.occurrences_between(Time.now, max_date.to_time)
93
97
  occurrences = []
94
98
  # Filter valid dates
95
99
  all_occurrences.each_with_index do |occurrence_date, index|
@@ -101,15 +105,23 @@ module Schedulable
101
105
  end
102
106
  end
103
107
  end
104
-
105
108
  else
106
- singular_date_time = schedule.date.to_datetime + schedule.time.seconds_since_midnight.seconds
109
+ # Get Singular occurrence
110
+ d = schedule.date
111
+ t = schedule.time
112
+ dt = d + t.seconds_since_midnight.seconds
113
+ singular_date_time = (d + t.seconds_since_midnight.seconds).to_datetime
107
114
  occurrences = [singular_date_time]
108
115
  end
109
-
116
+
110
117
  # Build occurrences
111
118
  update_mode = Schedulable.config.update_mode || :datetime
112
119
 
120
+ # Always use index as base for singular events
121
+ if schedule.rule == 'singular'
122
+ update_mode = :index
123
+ end
124
+
113
125
  # Get existing remaining records
114
126
  occurrences_records = schedulable.send("remaining_#{occurrences_association}")
115
127
 
@@ -118,7 +130,6 @@ module Schedulable
118
130
  occurrences.each_with_index do |occurrence, index|
119
131
 
120
132
  # Pull an existing record
121
-
122
133
  if update_mode == :index
123
134
  existing_records = [occurrences_records[index]]
124
135
  elsif update_mode == :datetime
@@ -133,13 +144,13 @@ module Schedulable
133
144
  # Overwrite existing records
134
145
  existing_records.each do |existing_record|
135
146
  if !occurrences_records.update(existing_record.id, date: occurrence.to_datetime)
136
- puts 'an error occurred while saving an existing occurrence record'
147
+ puts 'An error occurred while saving an existing occurrence record'
137
148
  end
138
149
  end
139
150
  else
140
151
  # Create new record
141
152
  if !occurrences_records.create(date: occurrence.to_datetime)
142
- puts 'an error occurred while creating an occurrence record'
153
+ puts 'An error occurred while creating an occurrence record'
143
154
  end
144
155
  end
145
156
  end
@@ -7,7 +7,7 @@ module Schedulable
7
7
 
8
8
  belongs_to :schedulable, polymorphic: true
9
9
 
10
- after_initialize :init_schedule
10
+ after_initialize :update_schedule
11
11
  before_save :update_schedule
12
12
 
13
13
  validates_presence_of :rule
@@ -25,7 +25,7 @@ module Schedulable
25
25
  end
26
26
 
27
27
  def method_missing(meth, *args, &block)
28
- if @schedule
28
+ if @schedule.present? && @schedule.respond_to?(meth)
29
29
  @schedule.send(meth, *args, &block)
30
30
  end
31
31
  end
@@ -35,13 +35,17 @@ module Schedulable
35
35
  end
36
36
 
37
37
  def update_schedule()
38
+
39
+ self.rule||= "singular"
40
+ self.interval||= 1
41
+ self.count||= 0
38
42
 
39
- date = self.date ? self.date.to_time : Time.now
40
- if self.time
41
- date = date.change({hour: self.time.hour, min: self.time.min})
43
+ time = Date.today.to_time
44
+ if self.time.present?
45
+ time = time + self.time.seconds_since_midnight.seconds
42
46
  end
43
-
44
- @schedule = IceCube::Schedule.new(date)
47
+
48
+ @schedule = IceCube::Schedule.new(time)
45
49
 
46
50
  if self.rule && self.rule != 'singular'
47
51
 
@@ -98,18 +102,6 @@ module Schedulable
98
102
  errors.add(:day_of_week, :empty)
99
103
  end
100
104
  end
101
-
102
-
103
- def init_schedule()
104
-
105
- self.rule||= "singular"
106
- self.interval||= 1
107
- self.count||= 0
108
-
109
- @schedule = IceCube::Schedule.new(date)
110
-
111
- self.update_schedule()
112
- end
113
105
  end
114
106
  end
115
107
  end
@@ -1,3 +1,3 @@
1
1
  module Schedulable
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'rake'
2
- desc 'builds occurrences for schedulable models'
2
+ desc 'Builds occurrences for schedulable models'
3
3
  namespace :schedulable do
4
4
  task :build_occurrences => :environment do
5
5
  Schedule.group(:schedulable_type).each do |schedule|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schedulable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafael Nowrotek
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-01 00:00:00.000000000 Z
11
+ date: 2015-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails