Class: Schedulable::Model::Schedule
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Schedulable::Model::Schedule
show all
- Defined in:
- lib/schedulable/schedule.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
27
28
29
30
31
|
# File 'lib/schedulable/schedule.rb', line 27
def method_missing(meth, *args, &block)
if @schedule.present? && @schedule.respond_to?(meth)
@schedule.send(meth, *args, &block)
end
end
|
Class Method Details
.param_names ⇒ Object
33
34
35
|
# File 'lib/schedulable/schedule.rb', line 33
def self.param_names
[:id, :date, :time, :rule, :until, :count, :interval, day: [], day_of_week: [monday: [], tuesday: [], wednesday: [], thursday: [], friday: [], saturday: [], sunday: []]]
end
|
Instance Method Details
#to_icecube ⇒ Object
19
20
21
|
# File 'lib/schedulable/schedule.rb', line 19
def to_icecube
return @schedule
end
|
#to_s ⇒ Object
23
24
25
|
# File 'lib/schedulable/schedule.rb', line 23
def to_s
return @schedule.to_s
end
|
#update_schedule ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/schedulable/schedule.rb', line 37
def update_schedule()
self.rule||= "singular"
self.interval||= 1
self.count||= 0
time = Date.today.to_time
if self.time.present?
time = time + self.time.seconds_since_midnight.seconds
end
@schedule = IceCube::Schedule.new(time)
if self.rule && self.rule != 'singular'
self.interval = self.interval.present? ? self.interval.to_i : 1
rule = IceCube::Rule.send("#{self.rule}", self.interval)
if self.until
rule.until(self.until)
end
if self.count && self.count.to_i > 0
rule.count(self.count.to_i)
end
if self.day
days = self.day.reject(&:empty?)
if self.rule == 'weekly'
days.each do |day|
rule.day(day.to_sym)
end
elsif self.rule == 'monthly'
days = {}
day_of_week.each do |weekday, value|
days[weekday.to_sym] = value.reject(&:empty?).map { |x| x.to_i }
end
rule.day_of_week(days)
end
end
@schedule.add_recurrence_rule(rule)
end
end
|