couch_visible 0.0.2 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,8 +11,8 @@ Given /^a document that is not shown$/ do
11
11
  @document = HiddenDoc.new.tap {|d| d.hide! and d.save }
12
12
  end
13
13
 
14
- When /^I call the "by_shown" method$/ do
15
- @result = TestDoc.by_shown :reduce => false
14
+ When /^I call the "map_by_shown" method$/ do
15
+ @result = TestDoc.map_by_shown.get!
16
16
  end
17
17
 
18
18
  Then /^I should receive the shown documents$/ do
@@ -27,8 +27,8 @@ Then /^I should not receive the hidden documents$/ do
27
27
 
28
28
  end
29
29
 
30
- When /^I call the "count_shown" method on my document model$/ do
31
- @result = TestDoc.count_shown
30
+ When /^I call the "count_by_shown" method on my document model$/ do
31
+ @result = TestDoc.count_by_shown!
32
32
  end
33
33
 
34
34
  Then /^I should receive the count of shown documents$/ do
@@ -578,8 +578,8 @@ x
578
578
  Given
579
579
  n
580
580
  s
581
- 30
582
- ^I call the "by_shown" method$
581
+ 34
582
+ ^I call the "map_by_shown" method$
583
583
  M
584
584
  1
585
585
  p
@@ -593,33 +593,21 @@ x
593
593
  9
594
594
  __block__
595
595
  i
596
- 24
596
+ 12
597
597
  45
598
598
  0
599
599
  1
600
- 44
601
- 43
602
- 2
603
- 79
604
600
  49
605
- 3
606
- 1
607
- 13
608
- 7
609
- 4
610
- 3
611
- 49
612
- 5
613
601
  2
614
- 15
602
+ 0
615
603
  49
616
- 6
617
- 1
604
+ 3
605
+ 0
618
606
  38
619
- 7
607
+ 4
620
608
  11
621
609
  I
622
- 6
610
+ 2
623
611
  I
624
612
  0
625
613
  I
@@ -629,26 +617,17 @@ I
629
617
  I
630
618
  -2
631
619
  p
632
- 8
620
+ 5
633
621
  x
634
622
  7
635
623
  TestDoc
636
624
  n
637
625
  x
638
- 4
639
- Hash
640
- x
641
- 16
642
- new_from_literal
643
- x
644
- 6
645
- reduce
646
- x
647
- 3
648
- []=
626
+ 12
627
+ map_by_shown
649
628
  x
650
- 8
651
- by_shown
629
+ 4
630
+ get!
652
631
  x
653
632
  7
654
633
  @result
@@ -659,7 +638,7 @@ I
659
638
  I
660
639
  f
661
640
  I
662
- 18
641
+ c
663
642
  x
664
643
  80
665
644
  /Users/mparker/work/github/couch_visible/features/step_definitions/show_steps.rb
@@ -982,8 +961,8 @@ p
982
961
  0
983
962
  n
984
963
  s
985
- 54
986
- ^I call the "count_shown" method on my document model$
964
+ 57
965
+ ^I call the "count_by_shown" method on my document model$
987
966
  M
988
967
  1
989
968
  p
@@ -1024,8 +1003,8 @@ x
1024
1003
  TestDoc
1025
1004
  n
1026
1005
  x
1027
- 11
1028
- count_shown
1006
+ 15
1007
+ count_by_shown!
1029
1008
  x
1030
1009
  7
1031
1010
  @result
@@ -2,7 +2,7 @@ $LOAD_PATH.unshift './lib'
2
2
 
3
3
  require 'couch_visible'
4
4
  require 'couchrest_model_config'
5
- require 'memories'
5
+ require 'couch_publish'
6
6
 
7
7
  class Document < CouchRest::Model::Base
8
8
  include CouchVisible
@@ -21,4 +21,10 @@ end
21
21
  Before do
22
22
  Document.database.recreate!
23
23
  CouchVisible.reset!
24
+
25
+ if defined? Query
26
+ Object.class_eval do
27
+ remove_const "Query"
28
+ end
29
+ end
24
30
  end
data/lib/couch_visible.rb CHANGED
@@ -1,2 +1,8 @@
1
+ require 'couch_view'
1
2
  require 'couch_visible/couch_visible'
3
+ require 'couch_visible/integrations/couch_publish'
4
+ require 'couch_visible/maps/by_hidden'
5
+ require 'couch_visible/maps/by_shown'
6
+ require 'couch_visible/conditions/published'
7
+ require 'couch_visible/conditions/unpublished'
2
8
  require 'couch_visible/config'
@@ -9,7 +9,7 @@ x
9
9
  10
10
10
  __script__
11
11
  i
12
- 20
12
+ 47
13
13
  5
14
14
  7
15
15
  0
@@ -28,6 +28,33 @@ i
28
28
  1
29
29
  1
30
30
  15
31
+ 5
32
+ 7
33
+ 3
34
+ 64
35
+ 47
36
+ 49
37
+ 1
38
+ 1
39
+ 15
40
+ 5
41
+ 7
42
+ 4
43
+ 64
44
+ 47
45
+ 49
46
+ 1
47
+ 1
48
+ 15
49
+ 5
50
+ 7
51
+ 5
52
+ 64
53
+ 47
54
+ 49
55
+ 1
56
+ 1
57
+ 15
31
58
  2
32
59
  11
33
60
  I
@@ -40,18 +67,27 @@ I
40
67
  0
41
68
  n
42
69
  p
43
- 3
70
+ 6
44
71
  s
45
- 27
46
- couch_visible/couch_visible
72
+ 10
73
+ couch_view
47
74
  x
48
75
  7
49
76
  require
50
77
  s
78
+ 27
79
+ couch_visible/couch_visible
80
+ s
81
+ 28
82
+ couch_visible/maps/by_hidden
83
+ s
84
+ 27
85
+ couch_visible/maps/by_shown
86
+ s
51
87
  20
52
88
  couch_visible/config
53
89
  p
54
- 5
90
+ 11
55
91
  I
56
92
  0
57
93
  I
@@ -61,7 +97,19 @@ I
61
97
  I
62
98
  2
63
99
  I
64
- 14
100
+ 12
101
+ I
102
+ 3
103
+ I
104
+ 1b
105
+ I
106
+ 4
107
+ I
108
+ 24
109
+ I
110
+ 5
111
+ I
112
+ 2f
65
113
  x
66
114
  61
67
115
  /Users/mparker/work/github/couch_visible/lib/couch_visible.rb
@@ -0,0 +1,9 @@
1
+ module CouchVisible
2
+ module Conditions
3
+ module Published
4
+ def conditions
5
+ "#{super} && doc.milestone_memories.length > 0"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module CouchVisible
2
+ module Conditions
3
+ module Unpublished
4
+ def conditions
5
+ "#{super} && doc.milestone_memories.length == 0"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,22 +1,17 @@
1
1
  module CouchVisible
2
2
 
3
3
  def self.included(base)
4
+ base.send :include, ::CouchView unless base.ancestors.include?(::CouchView)
4
5
  base.extend ModelClassMethods
5
6
  base.property :couch_visible, TrueClass
6
- base.view_by :hidden, :map => "
7
- function(doc){
8
- if (doc['couchrest-type'] == '#{base}' && doc.couch_visible == false){
9
- emit(doc['_id'], null);
10
- }
11
- }
12
- ", :reduce => "_count"
13
- base.view_by :shown, :map => "
14
- function(doc){
15
- if (doc['couchrest-type'] == '#{base}' && doc.couch_visible == true){
16
- emit(doc['_id'], null);
17
- }
18
- }
19
- ", :reduce => "_count"
7
+
8
+ base.couch_view :by_hidden do
9
+ map CouchVisible::ByHidden
10
+ end
11
+
12
+ base.couch_view :by_shown do
13
+ map CouchVisible::ByShown
14
+ end
20
15
 
21
16
  base.before_create do |doc|
22
17
  doc.couch_visible = doc.class.show_by_default? if doc.couch_visible.nil?
@@ -26,6 +21,10 @@ module CouchVisible
26
21
  if defined?(Memories) && base.ancestors.include?(Memories)
27
22
  base.forget :couch_visible
28
23
  end
24
+
25
+ if defined?(::CouchPublish) && base.ancestors.include?(::CouchPublish)
26
+ base.send :include, CouchVisible::CouchPublish
27
+ end
29
28
  end
30
29
 
31
30
  module ModelClassMethods
@@ -184,119 +184,80 @@ x
184
184
  8
185
185
  included
186
186
  i
187
- 169
187
+ 130
188
188
  20
189
189
  0
190
- 45
191
- 0
192
- 1
193
190
  49
194
- 2
195
- 1
196
- 15
197
- 20
198
191
  0
199
- 7
200
- 3
201
- 45
202
- 4
203
- 5
204
- 49
205
- 6
206
- 2
207
- 15
208
- 20
209
192
  0
210
- 7
211
- 7
212
193
  44
213
194
  43
214
- 8
215
- 80
195
+ 1
216
196
  49
197
+ 2
198
+ 1
217
199
  9
200
+ 16
218
201
  1
219
- 13
220
- 7
221
- 10
222
- 7
223
- 11
202
+ 8
203
+ 26
224
204
  20
225
205
  0
226
- 47
227
- 101
228
- 12
229
206
  7
230
- 13
231
- 63
232
207
  3
208
+ 44
209
+ 43
210
+ 1
233
211
  49
234
- 14
235
- 2
236
- 15
237
- 13
238
- 7
239
- 15
240
- 7
241
- 16
242
- 64
243
- 49
244
- 14
212
+ 4
245
213
  2
246
214
  15
215
+ 20
216
+ 0
217
+ 45
218
+ 5
219
+ 6
247
220
  49
248
- 17
249
- 2
221
+ 7
222
+ 1
250
223
  15
251
224
  20
252
225
  0
253
226
  7
254
- 18
255
- 44
256
- 43
257
227
  8
258
- 80
259
- 49
228
+ 45
260
229
  9
261
- 1
262
- 13
263
- 7
264
230
  10
265
- 7
231
+ 49
266
232
  11
233
+ 2
234
+ 15
267
235
  20
268
236
  0
269
- 47
270
- 101
271
- 12
272
237
  7
273
- 19
274
- 63
275
- 3
276
- 49
238
+ 12
239
+ 56
240
+ 13
241
+ 50
277
242
  14
278
- 2
243
+ 1
279
244
  15
280
- 13
245
+ 20
246
+ 0
281
247
  7
282
248
  15
283
- 7
249
+ 56
284
250
  16
285
- 64
286
- 49
251
+ 50
287
252
  14
288
- 2
289
- 15
290
- 49
291
- 17
292
- 2
253
+ 1
293
254
  15
294
255
  20
295
256
  0
296
257
  56
297
- 20
258
+ 17
298
259
  50
299
- 21
260
+ 18
300
261
  0
301
262
  15
302
263
  26
@@ -304,58 +265,58 @@ i
304
265
  0
305
266
  15
306
267
  29
307
- 129
268
+ 90
308
269
  0
309
270
  7
310
- 22
271
+ 19
311
272
  98
312
- 23
273
+ 20
313
274
  1
314
275
  30
315
276
  8
316
- 135
277
+ 96
317
278
  25
318
279
  92
319
280
  0
320
281
  27
321
282
  8
322
- 140
283
+ 101
323
284
  15
324
285
  7
325
- 24
286
+ 21
326
287
  8
327
- 141
288
+ 102
328
289
  1
329
290
  13
330
291
  9
331
- 156
292
+ 117
332
293
  15
333
294
  20
334
295
  0
335
296
  49
336
- 25
297
+ 0
337
298
  0
338
299
  45
300
+ 19
339
301
  22
340
- 26
341
302
  49
342
- 27
303
+ 2
343
304
  1
344
305
  9
345
- 167
306
+ 128
346
307
  20
347
308
  0
348
309
  7
349
- 3
310
+ 8
350
311
  49
351
- 28
312
+ 23
352
313
  1
353
314
  8
354
- 168
315
+ 129
355
316
  1
356
317
  11
357
318
  I
358
- a
319
+ 5
359
320
  I
360
321
  1
361
322
  I
@@ -364,7 +325,22 @@ I
364
325
  1
365
326
  n
366
327
  p
367
- 29
328
+ 24
329
+ x
330
+ 9
331
+ ancestors
332
+ x
333
+ 9
334
+ CouchView
335
+ x
336
+ 8
337
+ include?
338
+ x
339
+ 7
340
+ include
341
+ x
342
+ 4
343
+ send
368
344
  x
369
345
  17
370
346
  ModelClassMethods
@@ -383,54 +359,134 @@ x
383
359
  8
384
360
  property
385
361
  x
386
- 6
387
- hidden
362
+ 9
363
+ by_hidden
364
+ M
365
+ 1
366
+ p
367
+ 2
388
368
  x
369
+ 9
370
+ for_block
371
+ t
372
+ n
373
+ x
374
+ 8
375
+ included
376
+ i
377
+ 11
378
+ 5
379
+ 45
380
+ 0
381
+ 1
382
+ 43
383
+ 2
384
+ 47
385
+ 49
386
+ 3
387
+ 1
388
+ 11
389
+ I
390
+ 3
391
+ I
392
+ 0
393
+ I
394
+ 0
395
+ I
396
+ 0
397
+ I
398
+ -2
399
+ p
389
400
  4
390
- Hash
391
401
  x
392
- 16
393
- new_from_literal
402
+ 12
403
+ CouchVisible
404
+ n
405
+ x
406
+ 8
407
+ ByHidden
394
408
  x
395
409
  3
396
410
  map
397
- s
398
- 60
399
-
400
- function(doc){
401
- if (doc['couchrest-type'] == '
411
+ p
412
+ 3
413
+ I
414
+ 0
415
+ I
416
+ 9
417
+ I
418
+ b
402
419
  x
403
- 4
404
- to_s
405
- s
406
- 90
407
- ' && doc.couch_visible == false){
408
- emit(doc['_id'], null);
409
- }
410
- }
411
-
420
+ 75
421
+ /Users/mparker/work/github/couch_visible/lib/couch_visible/couch_visible.rb
422
+ p
423
+ 0
412
424
  x
425
+ 10
426
+ couch_view
427
+ x
428
+ 8
429
+ by_shown
430
+ M
431
+ 1
432
+ p
433
+ 2
434
+ x
435
+ 9
436
+ for_block
437
+ t
438
+ n
439
+ x
440
+ 8
441
+ included
442
+ i
443
+ 11
444
+ 5
445
+ 45
446
+ 0
447
+ 1
448
+ 43
449
+ 2
450
+ 47
451
+ 49
413
452
  3
414
- []=
453
+ 1
454
+ 11
455
+ I
456
+ 3
457
+ I
458
+ 0
459
+ I
460
+ 0
461
+ I
462
+ 0
463
+ I
464
+ -2
465
+ p
466
+ 4
415
467
  x
416
- 6
417
- reduce
418
- s
419
- 6
420
- _count
468
+ 12
469
+ CouchVisible
470
+ n
421
471
  x
422
472
  7
423
- view_by
473
+ ByShown
424
474
  x
425
- 5
426
- shown
427
- s
428
- 89
429
- ' && doc.couch_visible == true){
430
- emit(doc['_id'], null);
431
- }
432
- }
433
-
475
+ 3
476
+ map
477
+ p
478
+ 3
479
+ I
480
+ 0
481
+ I
482
+ d
483
+ I
484
+ b
485
+ x
486
+ 75
487
+ /Users/mparker/work/github/couch_visible/lib/couch_visible/couch_visible.rb
488
+ p
489
+ 0
434
490
  M
435
491
  1
436
492
  p
@@ -513,11 +569,11 @@ p
513
569
  I
514
570
  0
515
571
  I
516
- 15
572
+ 10
517
573
  I
518
574
  4
519
575
  I
520
- 16
576
+ 11
521
577
  I
522
578
  22
523
579
  I
@@ -525,7 +581,7 @@ I
525
581
  I
526
582
  23
527
583
  I
528
- 17
584
+ 12
529
585
  I
530
586
  25
531
587
  x
@@ -548,18 +604,12 @@ vm_const_defined
548
604
  s
549
605
  8
550
606
  constant
551
- x
552
- 9
553
- ancestors
554
607
  n
555
608
  x
556
- 8
557
- include?
558
- x
559
609
  6
560
610
  forget
561
611
  p
562
- 41
612
+ 25
563
613
  I
564
614
  -1
565
615
  I
@@ -569,79 +619,47 @@ I
569
619
  I
570
620
  4
571
621
  I
572
- 9
573
- I
574
- 5
575
- I
576
- 14
622
+ 1a
577
623
  I
578
- 6
624
+ 0
579
625
  I
580
- 18
626
+ 1b
581
627
  I
582
- c
628
+ 5
583
629
  I
584
- 20
630
+ 24
585
631
  I
586
632
  6
587
633
  I
588
- 24
634
+ 2f
589
635
  I
590
636
  8
591
637
  I
592
- 32
638
+ 39
593
639
  I
594
640
  c
595
641
  I
596
- 3b
597
- I
598
- 6
599
- I
600
- 3f
601
- I
602
- d
603
- I
604
642
  43
605
643
  I
606
- 13
644
+ 10
607
645
  I
608
646
  4b
609
647
  I
610
- d
611
- I
612
- 4f
613
- I
614
- f
615
- I
616
- 5d
617
- I
618
- 13
619
- I
620
- 66
621
- I
622
- d
623
- I
624
- 6a
625
- I
626
648
  15
627
649
  I
628
- 72
629
- I
630
- 1a
631
- I
632
- 9e
650
+ 77
633
651
  I
634
- 1b
652
+ 16
635
653
  I
636
- a7
654
+ 80
637
655
  I
638
- 1a
656
+ 15
639
657
  I
640
- a8
658
+ 81
641
659
  I
642
660
  0
643
661
  I
644
- a9
662
+ 82
645
663
  x
646
664
  75
647
665
  /Users/mparker/work/github/couch_visible/lib/couch_visible/couch_visible.rb
@@ -838,19 +856,19 @@ p
838
856
  I
839
857
  -1
840
858
  I
841
- 20
859
+ 1b
842
860
  I
843
861
  0
844
862
  I
845
- 21
863
+ 1c
846
864
  I
847
865
  f
848
866
  I
849
- 24
867
+ 1f
850
868
  I
851
869
  13
852
870
  I
853
- 22
871
+ 1d
854
872
  I
855
873
  19
856
874
  I
@@ -903,11 +921,11 @@ p
903
921
  I
904
922
  -1
905
923
  I
906
- 28
924
+ 23
907
925
  I
908
926
  0
909
927
  I
910
- 29
928
+ 24
911
929
  I
912
930
  4
913
931
  x
@@ -958,11 +976,11 @@ p
958
976
  I
959
977
  -1
960
978
  I
961
- 2c
979
+ 27
962
980
  I
963
981
  0
964
982
  I
965
- 2d
983
+ 28
966
984
  I
967
985
  c
968
986
  x
@@ -1005,11 +1023,11 @@ p
1005
1023
  I
1006
1024
  -1
1007
1025
  I
1008
- 30
1026
+ 2b
1009
1027
  I
1010
1028
  0
1011
1029
  I
1012
- 31
1030
+ 2c
1013
1031
  I
1014
1032
  4
1015
1033
  x
@@ -1120,15 +1138,15 @@ p
1120
1138
  I
1121
1139
  -1
1122
1140
  I
1123
- 34
1141
+ 2f
1124
1142
  I
1125
1143
  0
1126
1144
  I
1127
- 35
1145
+ 30
1128
1146
  I
1129
1147
  20
1130
1148
  I
1131
- 36
1149
+ 31
1132
1150
  I
1133
1151
  2f
1134
1152
  I
@@ -1246,15 +1264,15 @@ p
1246
1264
  I
1247
1265
  -1
1248
1266
  I
1249
- 39
1267
+ 34
1250
1268
  I
1251
1269
  0
1252
1270
  I
1253
- 3a
1271
+ 35
1254
1272
  I
1255
1273
  20
1256
1274
  I
1257
- 3b
1275
+ 36
1258
1276
  I
1259
1277
  2f
1260
1278
  I
@@ -1274,27 +1292,27 @@ p
1274
1292
  I
1275
1293
  2
1276
1294
  I
1277
- 20
1295
+ 1b
1278
1296
  I
1279
1297
  10
1280
1298
  I
1281
- 28
1299
+ 23
1282
1300
  I
1283
1301
  1e
1284
1302
  I
1285
- 2c
1303
+ 27
1286
1304
  I
1287
1305
  2c
1288
1306
  I
1289
- 30
1307
+ 2b
1290
1308
  I
1291
1309
  3a
1292
1310
  I
1293
- 34
1311
+ 2f
1294
1312
  I
1295
1313
  48
1296
1314
  I
1297
- 39
1315
+ 34
1298
1316
  I
1299
1317
  56
1300
1318
  x
@@ -1343,11 +1361,11 @@ p
1343
1361
  I
1344
1362
  -1
1345
1363
  I
1346
- 3f
1364
+ 3a
1347
1365
  I
1348
1366
  0
1349
1367
  I
1350
- 40
1368
+ 3b
1351
1369
  I
1352
1370
  7
1353
1371
  x
@@ -1408,11 +1426,11 @@ p
1408
1426
  I
1409
1427
  -1
1410
1428
  I
1411
- 43
1429
+ 3e
1412
1430
  I
1413
1431
  0
1414
1432
  I
1415
- 44
1433
+ 3f
1416
1434
  I
1417
1435
  d
1418
1436
  x
@@ -1462,15 +1480,15 @@ p
1462
1480
  I
1463
1481
  -1
1464
1482
  I
1465
- 47
1483
+ 42
1466
1484
  I
1467
1485
  0
1468
1486
  I
1469
- 4e
1487
+ 49
1470
1488
  I
1471
1489
  1
1472
1490
  I
1473
- 48
1491
+ 43
1474
1492
  I
1475
1493
  b
1476
1494
  x
@@ -1520,15 +1538,15 @@ p
1520
1538
  I
1521
1539
  -1
1522
1540
  I
1523
- 4b
1541
+ 46
1524
1542
  I
1525
1543
  0
1526
1544
  I
1527
- 4e
1545
+ 49
1528
1546
  I
1529
1547
  1
1530
1548
  I
1531
- 4c
1549
+ 47
1532
1550
  I
1533
1551
  b
1534
1552
  x
@@ -1545,23 +1563,23 @@ I
1545
1563
  I
1546
1564
  d
1547
1565
  I
1548
- 1f
1566
+ 1a
1549
1567
  I
1550
1568
  27
1551
1569
  I
1552
- 3f
1570
+ 3a
1553
1571
  I
1554
1572
  35
1555
1573
  I
1556
- 43
1574
+ 3e
1557
1575
  I
1558
1576
  43
1559
1577
  I
1560
- 47
1578
+ 42
1561
1579
  I
1562
1580
  51
1563
1581
  I
1564
- 4b
1582
+ 46
1565
1583
  I
1566
1584
  5f
1567
1585
  x