rails-scheduler 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/scheduler/model.rb +68 -70
- data/lib/scheduler/version.rb +1 -1
- metadata +12 -12
data/lib/scheduler/model.rb
CHANGED
@@ -24,92 +24,90 @@ module Scheduler
|
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
27
|
+
def frequency_sym
|
28
|
+
Scheduler::FREQUENCIES[frequency]
|
29
|
+
end
|
31
30
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
# Get [ 0, 1, 6 ] (monday, tuesday, sunday) from byte
|
32
|
+
def week_days
|
33
|
+
7.times.map{ |i|
|
34
|
+
days[i] > 0 ?
|
35
|
+
i :
|
36
|
+
nil
|
37
|
+
}.compact
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def week_day
|
41
|
+
week_days.first
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
def week_days_sym
|
45
|
+
week_days.map{ |d|
|
46
|
+
Date::DAYS_INTO_WEEK.invert[d]
|
47
|
+
}
|
48
|
+
end
|
50
49
|
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
def week_day_sym
|
51
|
+
week_days_sym.first
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
# Convert [ 0, 1, 6 ] (monday, tuesday, sunday) to byte
|
55
|
+
def week_days= ds
|
56
|
+
self.days =
|
57
|
+
ds.map{ |d| 2 ** d.to_i }.inject(0, &:+)
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
def week_day= day
|
61
|
+
self.week_days = Array.wrap(day)
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
def week_day_order
|
65
|
+
interval_flag
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
def week_day_order_sym
|
69
|
+
index = interval_flag
|
70
|
+
index -= 1 if index > 0
|
72
71
|
|
73
|
-
|
74
|
-
|
72
|
+
Scheduler::ORDER[index]
|
73
|
+
end
|
75
74
|
|
76
|
-
|
77
|
-
|
78
|
-
|
75
|
+
def week_day_order= order
|
76
|
+
self.interval_flag = order
|
77
|
+
end
|
79
78
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
79
|
+
# Array including all the dates this Scheduler has ocurrences
|
80
|
+
# between st and en
|
81
|
+
def ocurrences(st, en = nil)
|
82
|
+
recurrence ?
|
83
|
+
recurrence.events(:starts => st, :until => en) :
|
84
|
+
(start_at.to_date..end_at.to_date).to_a
|
85
|
+
end
|
87
86
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
87
|
+
def recurrence
|
88
|
+
case frequency_sym
|
89
|
+
when :weekly
|
90
|
+
Recurrence.new({ :every => :week,
|
91
|
+
:starts => start_date.to_date,
|
92
|
+
:until => end_date.try(:to_date),
|
93
|
+
:interval => interval,
|
94
|
+
:on => week_days_sym })
|
95
|
+
when :monthly
|
96
|
+
Recurrence.new({ :every => :month,
|
97
|
+
:starts => start_date.to_date,
|
98
|
+
:until => end_date.try(:to_date),
|
99
|
+
:interval => interval,
|
100
|
+
:on => week_day_order_sym,
|
101
|
+
:weekday => week_day_sym })
|
104
102
|
end
|
103
|
+
end
|
105
104
|
|
106
|
-
|
105
|
+
protected
|
107
106
|
|
108
|
-
|
109
|
-
|
107
|
+
def fill_scheduler_dates
|
108
|
+
self.start_date ||= start_at
|
110
109
|
|
111
|
-
|
112
|
-
end
|
110
|
+
self.end_date = end_at if frequency == 0
|
113
111
|
end
|
114
112
|
end
|
115
113
|
end
|
data/lib/scheduler/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-scheduler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-01-
|
12
|
+
date: 2012-01-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &72880910 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *72880910
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: recurrence
|
27
|
-
requirement: &
|
27
|
+
requirement: &72880630 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.2.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *72880630
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: mysql2
|
38
|
-
requirement: &
|
38
|
+
requirement: &72880420 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *72880420
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: factory_girl
|
49
|
-
requirement: &
|
49
|
+
requirement: &72880170 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *72880170
|
58
58
|
description: ! 'Scheduler support: daily, weekly and montly repetitions'
|
59
59
|
email:
|
60
60
|
- atapiador@dit.upm.es
|
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
segments:
|
137
137
|
- 0
|
138
|
-
hash:
|
138
|
+
hash: -203957359
|
139
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
140
|
none: false
|
141
141
|
requirements:
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
segments:
|
146
146
|
- 0
|
147
|
-
hash:
|
147
|
+
hash: -203957359
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
150
|
rubygems_version: 1.8.12
|