triggerable 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/triggerable/conditions/schedule/after.rb +5 -19
- data/lib/triggerable/conditions/schedule/before.rb +7 -27
- data/lib/triggerable/conditions/schedule/schedule_condition.rb +2 -4
- data/lib/triggerable/version.rb +1 -1
- data/spec/integration/automations_spec.rb +0 -156
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd600c99b81640a4f19345bb5fc2699449d18553
|
4
|
+
data.tar.gz: 97968a4541609b339a6fb840a69fd35a0ba1cc9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc8771acac90d02ea3fbea7dec517746d64f79865c6b7ba09165dde484ec73c134b6047fa725f5fa0c04bce18bc7561455b25571bb2a830ce517859ad37c9cda
|
7
|
+
data.tar.gz: 89dfb2ded39f4bec57136f221883d35c5e9f39e50f08a14432b9db9f6e98950e4eea32b3137b77402b40b801fcd4bfec611deacbbd3e5a18162da762a9b5e1cc
|
@@ -1,12 +1,7 @@
|
|
1
1
|
module Conditions
|
2
2
|
class After < ScheduleCondition
|
3
3
|
def from
|
4
|
-
|
5
|
-
when :greater_than, :less_than
|
6
|
-
Time.now - @value
|
7
|
-
when nil
|
8
|
-
automation_time - @value - Engine.interval
|
9
|
-
end
|
4
|
+
automation_time - @value - Engine.interval
|
10
5
|
end
|
11
6
|
|
12
7
|
def to
|
@@ -16,19 +11,10 @@ module Conditions
|
|
16
11
|
private
|
17
12
|
|
18
13
|
def condition
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
]
|
24
|
-
else
|
25
|
-
case @math_condition
|
26
|
-
when :greater_than
|
27
|
-
LessThanOrEqualTo.new(@field, from)
|
28
|
-
when :less_than
|
29
|
-
GreaterThanOrEqualTo.new(@field, from)
|
30
|
-
end
|
31
|
-
end
|
14
|
+
And.new [
|
15
|
+
GreaterThan.new(@field, from),
|
16
|
+
LessThanOrEqualTo.new(@field, to)
|
17
|
+
]
|
32
18
|
end
|
33
19
|
end
|
34
20
|
end
|
@@ -1,40 +1,20 @@
|
|
1
1
|
module Conditions
|
2
2
|
class Before < ScheduleCondition
|
3
3
|
def from
|
4
|
-
|
5
|
-
when :greater_than
|
6
|
-
Time.now
|
7
|
-
when :less_than
|
8
|
-
Time.now + @value
|
9
|
-
when nil
|
10
|
-
automation_time + @value
|
11
|
-
end
|
4
|
+
automation_time + @value
|
12
5
|
end
|
13
6
|
|
14
7
|
def to
|
15
|
-
|
16
|
-
when :greater_than
|
17
|
-
Time.now + @value
|
18
|
-
when nil
|
19
|
-
automation_time + @value + Engine.interval
|
20
|
-
end
|
8
|
+
automation_time + @value + Engine.interval
|
21
9
|
end
|
22
10
|
|
23
11
|
private
|
12
|
+
|
24
13
|
def condition
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
]
|
30
|
-
else
|
31
|
-
case @math_condition
|
32
|
-
when :greater_than
|
33
|
-
And.new([GreaterThanOrEqualTo.new(@field, from), LessThan.new(@field, to)])
|
34
|
-
when :less_than
|
35
|
-
GreaterThanOrEqualTo.new(@field, from)
|
36
|
-
end
|
37
|
-
end
|
14
|
+
And.new [
|
15
|
+
GreaterThanOrEqualTo.new(@field, from),
|
16
|
+
LessThan.new(@field, to)
|
17
|
+
]
|
38
18
|
end
|
39
19
|
end
|
40
20
|
end
|
@@ -1,11 +1,8 @@
|
|
1
1
|
module Conditions
|
2
2
|
class ScheduleCondition < FieldCondition
|
3
3
|
def initialize field, value
|
4
|
+
@value = value.values.first if value.is_a?(Hash)
|
4
5
|
super
|
5
|
-
if value.is_a?(Hash)
|
6
|
-
@math_condition = value.keys.first
|
7
|
-
@value = value.values.first
|
8
|
-
end
|
9
6
|
end
|
10
7
|
|
11
8
|
def true_for? object
|
@@ -17,6 +14,7 @@ module Conditions
|
|
17
14
|
end
|
18
15
|
|
19
16
|
protected
|
17
|
+
|
20
18
|
# automation_time is Time.now rounded by Engine.interval
|
21
19
|
def automation_time
|
22
20
|
i = Engine.interval
|
data/lib/triggerable/version.rb
CHANGED
@@ -194,160 +194,4 @@ describe 'Automations' do
|
|
194
194
|
Engine.run_automations(15.minutes)
|
195
195
|
expect(TestTask.count).to eq(2)
|
196
196
|
end
|
197
|
-
|
198
|
-
it 'after greater than 2 hours' do
|
199
|
-
constantize_time_now Time.utc 2012, 9, 1, 11, 55
|
200
|
-
|
201
|
-
TestTask.automation if: {and: [{updated_at: {after: {greater_than: 2.hours}}}, {status: {is: :solved}}, {kind: {is: :service}}]} do
|
202
|
-
TestTask.create kind: 'follow up'
|
203
|
-
end
|
204
|
-
|
205
|
-
task = TestTask.create
|
206
|
-
expect(TestTask.count).to eq(1)
|
207
|
-
task.update_attributes status: 'solved', kind: 'service'
|
208
|
-
expect(TestTask.count).to eq(1)
|
209
|
-
|
210
|
-
constantize_time_now Time.utc 2012, 9, 1, 12, 10
|
211
|
-
Engine.run_automations(15.minutes)
|
212
|
-
expect(TestTask.count).to eq(1)
|
213
|
-
|
214
|
-
constantize_time_now Time.utc 2012, 9, 1, 12, 25
|
215
|
-
Engine.run_automations(15.minutes)
|
216
|
-
expect(TestTask.count).to eq(1)
|
217
|
-
|
218
|
-
constantize_time_now Time.utc 2012, 9, 1, 13, 55
|
219
|
-
Engine.run_automations(15.minutes)
|
220
|
-
expect(TestTask.count).to eq(2)
|
221
|
-
expect(TestTask.all.last.kind).to eq('follow up')
|
222
|
-
|
223
|
-
constantize_time_now Time.utc 2012, 9, 1, 14, 10
|
224
|
-
Engine.run_automations(15.minutes)
|
225
|
-
expect(TestTask.count).to eq(3)
|
226
|
-
|
227
|
-
constantize_time_now Time.utc 2012, 9, 1, 14, 25
|
228
|
-
Engine.run_automations(15.minutes)
|
229
|
-
expect(TestTask.count).to eq(4)
|
230
|
-
end
|
231
|
-
|
232
|
-
it 'after less than 2 hours' do
|
233
|
-
constantize_time_now Time.utc 2012, 9, 1, 11, 55
|
234
|
-
|
235
|
-
TestTask.automation if: {and: [{updated_at: {after: {less_than: 2.hours}}}, {status: {is: :solved}}, {kind: {is: :service}}]} do
|
236
|
-
TestTask.create kind: 'follow up'
|
237
|
-
end
|
238
|
-
|
239
|
-
task = TestTask.create
|
240
|
-
expect(TestTask.count).to eq(1)
|
241
|
-
task.update_attributes status: 'solved', kind: 'service'
|
242
|
-
expect(TestTask.count).to eq(1)
|
243
|
-
|
244
|
-
constantize_time_now Time.utc 2012, 9, 1, 12, 10
|
245
|
-
Engine.run_automations(15.minutes)
|
246
|
-
expect(TestTask.count).to eq(2)
|
247
|
-
|
248
|
-
constantize_time_now Time.utc 2012, 9, 1, 12, 25
|
249
|
-
Engine.run_automations(15.minutes)
|
250
|
-
expect(TestTask.count).to eq(3)
|
251
|
-
|
252
|
-
constantize_time_now Time.utc 2012, 9, 1, 13, 55
|
253
|
-
Engine.run_automations(15.minutes)
|
254
|
-
expect(TestTask.count).to eq(4)
|
255
|
-
expect(TestTask.all.last.kind).to eq('follow up')
|
256
|
-
|
257
|
-
constantize_time_now Time.utc 2012, 9, 1, 14, 10
|
258
|
-
Engine.run_automations(15.minutes)
|
259
|
-
expect(TestTask.count).to eq(4)
|
260
|
-
|
261
|
-
constantize_time_now Time.utc 2012, 9, 1, 14, 25
|
262
|
-
Engine.run_automations(15.minutes)
|
263
|
-
expect(TestTask.count).to eq(4)
|
264
|
-
end
|
265
|
-
|
266
|
-
it 'before greater than 2 hours' do
|
267
|
-
constantize_time_now Time.utc 2012, 9, 1, 11, 55
|
268
|
-
|
269
|
-
TestTask.automation if: {and: [{scheduled_at: {before: {greater_than: 2.hours}}}, {status: {is: :solved}}, {kind: {is: :service}}]} do
|
270
|
-
TestTask.create kind: 'follow up'
|
271
|
-
end
|
272
|
-
|
273
|
-
task = TestTask.create scheduled_at: Time.utc(2012, 9, 1, 20, 00)
|
274
|
-
expect(TestTask.count).to eq(1)
|
275
|
-
task.update_attributes status: 'solved', kind: 'service'
|
276
|
-
expect(TestTask.count).to eq(1)
|
277
|
-
|
278
|
-
constantize_time_now Time.utc 2012, 9, 1, 12, 10
|
279
|
-
Engine.run_automations(15.minutes)
|
280
|
-
expect(TestTask.count).to eq(1)
|
281
|
-
|
282
|
-
constantize_time_now Time.utc 2012, 9, 1, 12, 25
|
283
|
-
Engine.run_automations(15.minutes)
|
284
|
-
expect(TestTask.count).to eq(1)
|
285
|
-
|
286
|
-
constantize_time_now Time.utc 2012, 9, 1, 17, 55
|
287
|
-
Engine.run_automations(15.minutes)
|
288
|
-
expect(TestTask.count).to eq(1)
|
289
|
-
|
290
|
-
constantize_time_now Time.utc 2012, 9, 1, 18, 00
|
291
|
-
Engine.run_automations(15.minutes)
|
292
|
-
expect(TestTask.count).to eq(1)
|
293
|
-
|
294
|
-
constantize_time_now Time.utc 2012, 9, 1, 18, 30
|
295
|
-
Engine.run_automations(15.minutes)
|
296
|
-
expect(TestTask.count).to eq(2)
|
297
|
-
expect(TestTask.all.last.kind).to eq('follow up')
|
298
|
-
|
299
|
-
constantize_time_now Time.utc 2012, 9, 1, 19, 55
|
300
|
-
Engine.run_automations(15.minutes)
|
301
|
-
expect(TestTask.count).to eq(3)
|
302
|
-
|
303
|
-
constantize_time_now Time.utc 2012, 9, 1, 20, 00
|
304
|
-
Engine.run_automations(15.minutes)
|
305
|
-
expect(TestTask.count).to eq(4)
|
306
|
-
|
307
|
-
constantize_time_now Time.utc 2012, 9, 1, 20, 05
|
308
|
-
Engine.run_automations(15.minutes)
|
309
|
-
expect(TestTask.count).to eq(4)
|
310
|
-
|
311
|
-
constantize_time_now Time.utc 2012, 9, 1, 20, 10
|
312
|
-
Engine.run_automations(15.minutes)
|
313
|
-
expect(TestTask.count).to eq(4)
|
314
|
-
end
|
315
|
-
|
316
|
-
it 'before less than 2 hours' do
|
317
|
-
constantize_time_now Time.utc 2012, 9, 1, 11, 55
|
318
|
-
|
319
|
-
TestTask.automation if: {and: [{scheduled_at: {before: {less_than: 2.hours}}}, {status: {is: :solved}}, {kind: {is: :service}}]} do
|
320
|
-
TestTask.create kind: 'follow up'
|
321
|
-
end
|
322
|
-
|
323
|
-
task = TestTask.create scheduled_at: Time.utc(2012, 9, 1, 20, 00)
|
324
|
-
expect(TestTask.count).to eq(1)
|
325
|
-
task.update_attributes status: 'solved', kind: 'service'
|
326
|
-
expect(TestTask.count).to eq(1)
|
327
|
-
|
328
|
-
constantize_time_now Time.utc 2012, 9, 1, 12, 10
|
329
|
-
Engine.run_automations(15.minutes)
|
330
|
-
expect(TestTask.count).to eq(2)
|
331
|
-
|
332
|
-
constantize_time_now Time.utc 2012, 9, 1, 12, 25
|
333
|
-
Engine.run_automations(15.minutes)
|
334
|
-
expect(TestTask.count).to eq(3)
|
335
|
-
|
336
|
-
constantize_time_now Time.utc 2012, 9, 1, 17, 55
|
337
|
-
Engine.run_automations(15.minutes)
|
338
|
-
expect(TestTask.count).to eq(4)
|
339
|
-
|
340
|
-
constantize_time_now Time.utc 2012, 9, 1, 18, 00
|
341
|
-
Engine.run_automations(15.minutes)
|
342
|
-
expect(TestTask.count).to eq(5)
|
343
|
-
expect(TestTask.all.last.kind).to eq('follow up')
|
344
|
-
|
345
|
-
constantize_time_now Time.utc 2012, 9, 1, 18, 30
|
346
|
-
Engine.run_automations(15.minutes)
|
347
|
-
expect(TestTask.count).to eq(5)
|
348
|
-
|
349
|
-
constantize_time_now Time.utc 2012, 9, 1, 18, 40
|
350
|
-
Engine.run_automations(15.minutes)
|
351
|
-
expect(TestTask.count).to eq(5)
|
352
|
-
end
|
353
197
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: triggerable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DmitryTsepelev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|