primer 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +17 -0
- data/README.rdoc +74 -35
- data/example/README.rdoc +33 -23
- data/example/application.rb +2 -2
- data/example/console.rb +133 -0
- data/example/db/blog.sqlite3 +0 -0
- data/example/{models → db}/connection.rb +0 -0
- data/example/environment.rb +17 -4
- data/example/models/comment.rb +5 -0
- data/example/models/post.rb +5 -0
- data/example/script/setup_database.rb +8 -2
- data/example/views/comments.erb +6 -0
- data/example/views/layout.erb +1 -1
- data/example/views/show.erb +5 -1
- data/lib/primer/bus/amqp.rb +7 -5
- data/lib/primer/bus/amqp.rbc +1045 -0
- data/lib/primer/bus/memory.rbc +344 -0
- data/lib/primer/bus.rb +3 -2
- data/lib/primer/bus.rbc +872 -0
- data/lib/primer/cache/memory.rbc +1443 -0
- data/lib/primer/cache/redis.rb +2 -2
- data/lib/primer/cache/redis.rbc +1643 -0
- data/lib/primer/cache.rb +2 -16
- data/lib/primer/cache.rbc +1502 -0
- data/lib/primer/enabler.rbc +414 -0
- data/lib/primer/helpers.rbc +1438 -0
- data/lib/primer/lazyness.rb +63 -0
- data/lib/primer/lazyness.rbc +1442 -0
- data/lib/primer/real_time.rbc +1999 -0
- data/lib/primer/route_set.rb +1 -0
- data/lib/primer/route_set.rbc +1475 -0
- data/lib/primer/watcher/active_record_macros.rb +13 -3
- data/lib/primer/watcher/active_record_macros.rbc +1796 -0
- data/lib/primer/watcher/macros.rb +11 -14
- data/lib/primer/watcher/macros.rbc +1628 -0
- data/lib/primer/watcher.rb +2 -7
- data/lib/primer/watcher.rbc +1416 -0
- data/lib/primer/worker/active_record_agent.rb +30 -33
- data/lib/primer/worker/active_record_agent.rbc +2840 -0
- data/lib/primer/worker/changes_agent.rb +20 -0
- data/lib/primer/worker/changes_agent.rbc +578 -0
- data/lib/primer/worker.rb +20 -3
- data/lib/primer/worker.rbc +1254 -0
- data/lib/primer.rb +10 -2
- data/lib/primer.rbc +944 -0
- data/spec/db/test.sqlite3 +0 -0
- data/spec/models/artist.rb +3 -2
- data/spec/models/artist.rbc +288 -0
- data/spec/models/blog_post.rb +3 -1
- data/spec/models/blog_post.rbc +181 -0
- data/spec/models/calendar.rbc +209 -0
- data/spec/models/concert.rbc +211 -0
- data/spec/models/performance.rbc +177 -0
- data/spec/models/person.rb +1 -0
- data/spec/models/person.rbc +306 -0
- data/spec/models/watchable.rbc +363 -0
- data/spec/primer/bus_spec.rbc +940 -0
- data/spec/primer/cache_spec.rb +3 -3
- data/spec/primer/cache_spec.rbc +8535 -0
- data/spec/primer/helpers/erb_spec.rb +14 -14
- data/spec/primer/helpers/erb_spec.rbc +2485 -0
- data/spec/primer/lazyness_spec.rb +61 -0
- data/spec/primer/lazyness_spec.rbc +1408 -0
- data/spec/primer/watcher/active_record_spec.rb +15 -15
- data/spec/primer/watcher/active_record_spec.rbc +5202 -0
- data/spec/primer/watcher_spec.rbc +2645 -0
- data/spec/schema.rbc +775 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/spec_helper.rbc +1193 -0
- data/spec/templates/page.erb +0 -1
- metadata +77 -70
- data/example/models/blog_post.rb +0 -4
@@ -0,0 +1,20 @@
|
|
1
|
+
module Primer
|
2
|
+
class Worker
|
3
|
+
|
4
|
+
class ChangesAgent < Agent
|
5
|
+
topic :changes
|
6
|
+
|
7
|
+
def on_message(attribute)
|
8
|
+
cache = Primer.cache
|
9
|
+
cache.keys_for_attribute(attribute).each do |cache_key|
|
10
|
+
block = lambda do
|
11
|
+
cache.invalidate(cache_key)
|
12
|
+
cache.regenerate(cache_key)
|
13
|
+
end
|
14
|
+
cache.throttle ? cache.timeout(cache_key, &block) : block.call
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,578 @@
|
|
1
|
+
!RBIX
|
2
|
+
10310238139619683799
|
3
|
+
x
|
4
|
+
M
|
5
|
+
1
|
6
|
+
n
|
7
|
+
n
|
8
|
+
x
|
9
|
+
10
|
10
|
+
__script__
|
11
|
+
i
|
12
|
+
28
|
13
|
+
99
|
14
|
+
7
|
15
|
+
0
|
16
|
+
65
|
17
|
+
49
|
18
|
+
1
|
19
|
+
2
|
20
|
+
13
|
21
|
+
99
|
22
|
+
12
|
23
|
+
7
|
24
|
+
2
|
25
|
+
12
|
26
|
+
7
|
27
|
+
3
|
28
|
+
12
|
29
|
+
65
|
30
|
+
12
|
31
|
+
49
|
32
|
+
4
|
33
|
+
4
|
34
|
+
15
|
35
|
+
49
|
36
|
+
2
|
37
|
+
0
|
38
|
+
15
|
39
|
+
2
|
40
|
+
11
|
41
|
+
I
|
42
|
+
6
|
43
|
+
I
|
44
|
+
0
|
45
|
+
I
|
46
|
+
0
|
47
|
+
I
|
48
|
+
0
|
49
|
+
n
|
50
|
+
p
|
51
|
+
5
|
52
|
+
x
|
53
|
+
6
|
54
|
+
Primer
|
55
|
+
x
|
56
|
+
11
|
57
|
+
open_module
|
58
|
+
x
|
59
|
+
15
|
60
|
+
__module_init__
|
61
|
+
M
|
62
|
+
1
|
63
|
+
n
|
64
|
+
n
|
65
|
+
x
|
66
|
+
6
|
67
|
+
Primer
|
68
|
+
i
|
69
|
+
29
|
70
|
+
5
|
71
|
+
66
|
72
|
+
99
|
73
|
+
7
|
74
|
+
0
|
75
|
+
1
|
76
|
+
65
|
77
|
+
49
|
78
|
+
1
|
79
|
+
3
|
80
|
+
13
|
81
|
+
99
|
82
|
+
12
|
83
|
+
7
|
84
|
+
2
|
85
|
+
12
|
86
|
+
7
|
87
|
+
3
|
88
|
+
12
|
89
|
+
65
|
90
|
+
12
|
91
|
+
49
|
92
|
+
4
|
93
|
+
4
|
94
|
+
15
|
95
|
+
49
|
96
|
+
2
|
97
|
+
0
|
98
|
+
11
|
99
|
+
I
|
100
|
+
6
|
101
|
+
I
|
102
|
+
0
|
103
|
+
I
|
104
|
+
0
|
105
|
+
I
|
106
|
+
0
|
107
|
+
n
|
108
|
+
p
|
109
|
+
5
|
110
|
+
x
|
111
|
+
6
|
112
|
+
Worker
|
113
|
+
x
|
114
|
+
10
|
115
|
+
open_class
|
116
|
+
x
|
117
|
+
14
|
118
|
+
__class_init__
|
119
|
+
M
|
120
|
+
1
|
121
|
+
n
|
122
|
+
n
|
123
|
+
x
|
124
|
+
6
|
125
|
+
Worker
|
126
|
+
i
|
127
|
+
31
|
128
|
+
5
|
129
|
+
66
|
130
|
+
99
|
131
|
+
7
|
132
|
+
0
|
133
|
+
45
|
134
|
+
1
|
135
|
+
2
|
136
|
+
65
|
137
|
+
49
|
138
|
+
3
|
139
|
+
3
|
140
|
+
13
|
141
|
+
99
|
142
|
+
12
|
143
|
+
7
|
144
|
+
4
|
145
|
+
12
|
146
|
+
7
|
147
|
+
5
|
148
|
+
12
|
149
|
+
65
|
150
|
+
12
|
151
|
+
49
|
152
|
+
6
|
153
|
+
4
|
154
|
+
15
|
155
|
+
49
|
156
|
+
4
|
157
|
+
0
|
158
|
+
11
|
159
|
+
I
|
160
|
+
6
|
161
|
+
I
|
162
|
+
0
|
163
|
+
I
|
164
|
+
0
|
165
|
+
I
|
166
|
+
0
|
167
|
+
n
|
168
|
+
p
|
169
|
+
7
|
170
|
+
x
|
171
|
+
12
|
172
|
+
ChangesAgent
|
173
|
+
x
|
174
|
+
5
|
175
|
+
Agent
|
176
|
+
n
|
177
|
+
x
|
178
|
+
10
|
179
|
+
open_class
|
180
|
+
x
|
181
|
+
14
|
182
|
+
__class_init__
|
183
|
+
M
|
184
|
+
1
|
185
|
+
n
|
186
|
+
n
|
187
|
+
x
|
188
|
+
12
|
189
|
+
ChangesAgent
|
190
|
+
i
|
191
|
+
24
|
192
|
+
5
|
193
|
+
66
|
194
|
+
5
|
195
|
+
7
|
196
|
+
0
|
197
|
+
47
|
198
|
+
49
|
199
|
+
1
|
200
|
+
1
|
201
|
+
15
|
202
|
+
99
|
203
|
+
7
|
204
|
+
2
|
205
|
+
7
|
206
|
+
3
|
207
|
+
65
|
208
|
+
67
|
209
|
+
49
|
210
|
+
4
|
211
|
+
0
|
212
|
+
49
|
213
|
+
5
|
214
|
+
4
|
215
|
+
11
|
216
|
+
I
|
217
|
+
5
|
218
|
+
I
|
219
|
+
0
|
220
|
+
I
|
221
|
+
0
|
222
|
+
I
|
223
|
+
0
|
224
|
+
n
|
225
|
+
p
|
226
|
+
6
|
227
|
+
x
|
228
|
+
7
|
229
|
+
changes
|
230
|
+
x
|
231
|
+
5
|
232
|
+
topic
|
233
|
+
x
|
234
|
+
10
|
235
|
+
on_message
|
236
|
+
M
|
237
|
+
1
|
238
|
+
n
|
239
|
+
n
|
240
|
+
x
|
241
|
+
10
|
242
|
+
on_message
|
243
|
+
i
|
244
|
+
22
|
245
|
+
45
|
246
|
+
0
|
247
|
+
1
|
248
|
+
49
|
249
|
+
2
|
250
|
+
0
|
251
|
+
19
|
252
|
+
1
|
253
|
+
15
|
254
|
+
20
|
255
|
+
1
|
256
|
+
20
|
257
|
+
0
|
258
|
+
49
|
259
|
+
3
|
260
|
+
1
|
261
|
+
56
|
262
|
+
4
|
263
|
+
50
|
264
|
+
5
|
265
|
+
0
|
266
|
+
11
|
267
|
+
I
|
268
|
+
4
|
269
|
+
I
|
270
|
+
2
|
271
|
+
I
|
272
|
+
1
|
273
|
+
I
|
274
|
+
1
|
275
|
+
n
|
276
|
+
p
|
277
|
+
6
|
278
|
+
x
|
279
|
+
6
|
280
|
+
Primer
|
281
|
+
n
|
282
|
+
x
|
283
|
+
5
|
284
|
+
cache
|
285
|
+
x
|
286
|
+
18
|
287
|
+
keys_for_attribute
|
288
|
+
M
|
289
|
+
1
|
290
|
+
p
|
291
|
+
2
|
292
|
+
x
|
293
|
+
9
|
294
|
+
for_block
|
295
|
+
t
|
296
|
+
n
|
297
|
+
x
|
298
|
+
10
|
299
|
+
on_message
|
300
|
+
i
|
301
|
+
51
|
302
|
+
57
|
303
|
+
19
|
304
|
+
0
|
305
|
+
15
|
306
|
+
5
|
307
|
+
56
|
308
|
+
0
|
309
|
+
47
|
310
|
+
50
|
311
|
+
1
|
312
|
+
0
|
313
|
+
19
|
314
|
+
1
|
315
|
+
15
|
316
|
+
21
|
317
|
+
1
|
318
|
+
1
|
319
|
+
49
|
320
|
+
2
|
321
|
+
0
|
322
|
+
9
|
323
|
+
45
|
324
|
+
21
|
325
|
+
1
|
326
|
+
1
|
327
|
+
20
|
328
|
+
0
|
329
|
+
20
|
330
|
+
1
|
331
|
+
13
|
332
|
+
70
|
333
|
+
10
|
334
|
+
40
|
335
|
+
44
|
336
|
+
43
|
337
|
+
3
|
338
|
+
12
|
339
|
+
49
|
340
|
+
4
|
341
|
+
1
|
342
|
+
50
|
343
|
+
5
|
344
|
+
1
|
345
|
+
8
|
346
|
+
50
|
347
|
+
20
|
348
|
+
1
|
349
|
+
49
|
350
|
+
6
|
351
|
+
0
|
352
|
+
11
|
353
|
+
I
|
354
|
+
7
|
355
|
+
I
|
356
|
+
2
|
357
|
+
I
|
358
|
+
1
|
359
|
+
I
|
360
|
+
1
|
361
|
+
n
|
362
|
+
p
|
363
|
+
7
|
364
|
+
M
|
365
|
+
1
|
366
|
+
p
|
367
|
+
2
|
368
|
+
x
|
369
|
+
9
|
370
|
+
for_block
|
371
|
+
t
|
372
|
+
n
|
373
|
+
x
|
374
|
+
10
|
375
|
+
on_message
|
376
|
+
i
|
377
|
+
20
|
378
|
+
21
|
379
|
+
2
|
380
|
+
1
|
381
|
+
21
|
382
|
+
1
|
383
|
+
0
|
384
|
+
49
|
385
|
+
0
|
386
|
+
1
|
387
|
+
15
|
388
|
+
21
|
389
|
+
2
|
390
|
+
1
|
391
|
+
21
|
392
|
+
1
|
393
|
+
0
|
394
|
+
49
|
395
|
+
1
|
396
|
+
1
|
397
|
+
11
|
398
|
+
I
|
399
|
+
3
|
400
|
+
I
|
401
|
+
0
|
402
|
+
I
|
403
|
+
0
|
404
|
+
I
|
405
|
+
0
|
406
|
+
I
|
407
|
+
-2
|
408
|
+
p
|
409
|
+
2
|
410
|
+
x
|
411
|
+
10
|
412
|
+
invalidate
|
413
|
+
x
|
414
|
+
10
|
415
|
+
regenerate
|
416
|
+
p
|
417
|
+
5
|
418
|
+
I
|
419
|
+
0
|
420
|
+
I
|
421
|
+
b
|
422
|
+
I
|
423
|
+
a
|
424
|
+
I
|
425
|
+
c
|
426
|
+
I
|
427
|
+
14
|
428
|
+
x
|
429
|
+
65
|
430
|
+
/Users/jcoglan/projects/primer/lib/primer/worker/changes_agent.rb
|
431
|
+
p
|
432
|
+
0
|
433
|
+
x
|
434
|
+
6
|
435
|
+
lambda
|
436
|
+
x
|
437
|
+
8
|
438
|
+
throttle
|
439
|
+
x
|
440
|
+
4
|
441
|
+
Proc
|
442
|
+
x
|
443
|
+
14
|
444
|
+
__from_block__
|
445
|
+
x
|
446
|
+
7
|
447
|
+
timeout
|
448
|
+
x
|
449
|
+
4
|
450
|
+
call
|
451
|
+
p
|
452
|
+
7
|
453
|
+
I
|
454
|
+
0
|
455
|
+
I
|
456
|
+
9
|
457
|
+
I
|
458
|
+
4
|
459
|
+
I
|
460
|
+
a
|
461
|
+
I
|
462
|
+
e
|
463
|
+
I
|
464
|
+
e
|
465
|
+
I
|
466
|
+
33
|
467
|
+
x
|
468
|
+
65
|
469
|
+
/Users/jcoglan/projects/primer/lib/primer/worker/changes_agent.rb
|
470
|
+
p
|
471
|
+
2
|
472
|
+
x
|
473
|
+
9
|
474
|
+
cache_key
|
475
|
+
x
|
476
|
+
5
|
477
|
+
block
|
478
|
+
x
|
479
|
+
4
|
480
|
+
each
|
481
|
+
p
|
482
|
+
7
|
483
|
+
I
|
484
|
+
-1
|
485
|
+
I
|
486
|
+
7
|
487
|
+
I
|
488
|
+
0
|
489
|
+
I
|
490
|
+
8
|
491
|
+
I
|
492
|
+
9
|
493
|
+
I
|
494
|
+
9
|
495
|
+
I
|
496
|
+
16
|
497
|
+
x
|
498
|
+
65
|
499
|
+
/Users/jcoglan/projects/primer/lib/primer/worker/changes_agent.rb
|
500
|
+
p
|
501
|
+
2
|
502
|
+
x
|
503
|
+
9
|
504
|
+
attribute
|
505
|
+
x
|
506
|
+
5
|
507
|
+
cache
|
508
|
+
x
|
509
|
+
17
|
510
|
+
method_visibility
|
511
|
+
x
|
512
|
+
15
|
513
|
+
add_defn_method
|
514
|
+
p
|
515
|
+
5
|
516
|
+
I
|
517
|
+
2
|
518
|
+
I
|
519
|
+
5
|
520
|
+
I
|
521
|
+
a
|
522
|
+
I
|
523
|
+
7
|
524
|
+
I
|
525
|
+
18
|
526
|
+
x
|
527
|
+
65
|
528
|
+
/Users/jcoglan/projects/primer/lib/primer/worker/changes_agent.rb
|
529
|
+
p
|
530
|
+
0
|
531
|
+
x
|
532
|
+
13
|
533
|
+
attach_method
|
534
|
+
p
|
535
|
+
3
|
536
|
+
I
|
537
|
+
2
|
538
|
+
I
|
539
|
+
4
|
540
|
+
I
|
541
|
+
1f
|
542
|
+
x
|
543
|
+
65
|
544
|
+
/Users/jcoglan/projects/primer/lib/primer/worker/changes_agent.rb
|
545
|
+
p
|
546
|
+
0
|
547
|
+
x
|
548
|
+
13
|
549
|
+
attach_method
|
550
|
+
p
|
551
|
+
3
|
552
|
+
I
|
553
|
+
2
|
554
|
+
I
|
555
|
+
2
|
556
|
+
I
|
557
|
+
1d
|
558
|
+
x
|
559
|
+
65
|
560
|
+
/Users/jcoglan/projects/primer/lib/primer/worker/changes_agent.rb
|
561
|
+
p
|
562
|
+
0
|
563
|
+
x
|
564
|
+
13
|
565
|
+
attach_method
|
566
|
+
p
|
567
|
+
3
|
568
|
+
I
|
569
|
+
0
|
570
|
+
I
|
571
|
+
1
|
572
|
+
I
|
573
|
+
1c
|
574
|
+
x
|
575
|
+
65
|
576
|
+
/Users/jcoglan/projects/primer/lib/primer/worker/changes_agent.rb
|
577
|
+
p
|
578
|
+
0
|
data/lib/primer/worker.rb
CHANGED
@@ -3,9 +3,26 @@ module Primer
|
|
3
3
|
|
4
4
|
class ConfigError < StandardError ; end
|
5
5
|
|
6
|
+
class Agent
|
7
|
+
def self.run!
|
8
|
+
agent = new
|
9
|
+
agent.run!
|
10
|
+
agent
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.topic(topic_name = nil)
|
14
|
+
@topic_name ||= topic_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def run!
|
18
|
+
Primer.bus.subscribe(self.class.topic) { |m| on_message(m) }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
6
22
|
autoload :ActiveRecordAgent, ROOT + '/primer/worker/active_record_agent'
|
23
|
+
autoload :ChangesAgent, ROOT + '/primer/worker/changes_agent'
|
7
24
|
|
8
|
-
def run
|
25
|
+
def run!
|
9
26
|
raise ConfigError.new('No cache present') unless Primer.cache
|
10
27
|
raise ConfigError.new('No message bus present') unless Primer.bus
|
11
28
|
|
@@ -21,8 +38,8 @@ module Primer
|
|
21
38
|
puts "[changes] #{ args.inspect }"
|
22
39
|
end
|
23
40
|
|
24
|
-
ActiveRecordAgent.
|
25
|
-
|
41
|
+
ActiveRecordAgent.run!
|
42
|
+
ChangesAgent.run!
|
26
43
|
|
27
44
|
puts "Listening for messages..."
|
28
45
|
puts
|