couch_visible 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -0
- data/features/configuration.feature +57 -0
- data/features/hide.feature +29 -0
- data/features/memories_integration.feature +9 -0
- data/features/show.feature +29 -0
- data/features/step_definitions/configuration_steps.rb +57 -0
- data/features/step_definitions/configuration_steps.rbc +1500 -0
- data/features/step_definitions/hide_steps.rb +58 -0
- data/features/step_definitions/hide_steps.rbc +1907 -0
- data/features/step_definitions/memories_integration_steps.rb +13 -0
- data/features/step_definitions/memories_integration_steps.rbc +447 -0
- data/features/step_definitions/show_steps.rb +36 -0
- data/features/step_definitions/show_steps.rbc +1152 -0
- data/features/support/env.rb +24 -0
- data/features/support/env.rbc +518 -0
- data/lib/couch_visible/config.rb +25 -0
- data/lib/couch_visible/config.rbc +553 -0
- data/lib/couch_visible/couch_visible.rb +78 -0
- data/lib/couch_visible/couch_visible.rbc +1587 -0
- data/lib/couch_visible.rb +2 -0
- data/lib/couch_visible.rbc +69 -0
- data/readme.markdown +118 -0
- metadata +42 -8
@@ -0,0 +1,69 @@
|
|
1
|
+
!RBIX
|
2
|
+
17831730954501249321
|
3
|
+
x
|
4
|
+
M
|
5
|
+
1
|
6
|
+
n
|
7
|
+
n
|
8
|
+
x
|
9
|
+
10
|
10
|
+
__script__
|
11
|
+
i
|
12
|
+
20
|
13
|
+
5
|
14
|
+
7
|
15
|
+
0
|
16
|
+
64
|
17
|
+
47
|
18
|
+
49
|
19
|
+
1
|
20
|
+
1
|
21
|
+
15
|
22
|
+
5
|
23
|
+
7
|
24
|
+
2
|
25
|
+
64
|
26
|
+
47
|
27
|
+
49
|
28
|
+
1
|
29
|
+
1
|
30
|
+
15
|
31
|
+
2
|
32
|
+
11
|
33
|
+
I
|
34
|
+
2
|
35
|
+
I
|
36
|
+
0
|
37
|
+
I
|
38
|
+
0
|
39
|
+
I
|
40
|
+
0
|
41
|
+
n
|
42
|
+
p
|
43
|
+
3
|
44
|
+
s
|
45
|
+
27
|
46
|
+
couch_visible/couch_visible
|
47
|
+
x
|
48
|
+
7
|
49
|
+
require
|
50
|
+
s
|
51
|
+
20
|
52
|
+
couch_visible/config
|
53
|
+
p
|
54
|
+
5
|
55
|
+
I
|
56
|
+
0
|
57
|
+
I
|
58
|
+
1
|
59
|
+
I
|
60
|
+
9
|
61
|
+
I
|
62
|
+
2
|
63
|
+
I
|
64
|
+
14
|
65
|
+
x
|
66
|
+
61
|
67
|
+
/Users/mparker/work/github/couch_visible/lib/couch_visible.rb
|
68
|
+
p
|
69
|
+
0
|
data/readme.markdown
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
# CouchVisible
|
2
|
+
|
3
|
+
CouchVisible is a mixin for your CouchRest::Model documents that provides a simple API for specifying the visibility of a document. This comes in handy in content publishing systems where you want to be able to hide and show documents on your website.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
It's a gem. Either run `gem install couch_visible` at the command line, or add `gem 'couch_visible'` to your Gemfile.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
The gem provides a mixin `CouchVisible` for your `CouchRest::Model::Base` derived documents:
|
12
|
+
|
13
|
+
class Article < CouchRest::Model::Base
|
14
|
+
include CouchVisible
|
15
|
+
end
|
16
|
+
|
17
|
+
### Hidden by default
|
18
|
+
|
19
|
+
Mixing it into your document will create a boolean "couch_visible" property on your document. By default, documents will be hidden; if you'd prefer your documents to be visible by default, simply use the `show_by_default!` macro:
|
20
|
+
|
21
|
+
class Article < CouchRest::Model::Base
|
22
|
+
include CouchVisible
|
23
|
+
show_by_default!
|
24
|
+
end
|
25
|
+
|
26
|
+
You can also configure this globally:
|
27
|
+
|
28
|
+
CouchVisible.show_by_default!
|
29
|
+
|
30
|
+
Now, all document models that include CouchVisible will be shown by default. They could override the global default by calling "hide_by_default!":
|
31
|
+
|
32
|
+
class Post < CouchRest::Model::Base
|
33
|
+
include CouchVisible
|
34
|
+
hide_by_default!
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
### Showing and Hiding Documents
|
39
|
+
|
40
|
+
`CouchVisible` lets you toggle the visibility of documents via `show!` and `hide!` methods:
|
41
|
+
|
42
|
+
a = Article.first
|
43
|
+
|
44
|
+
a.hide!
|
45
|
+
#==> sets the couch_visible property to false and saves the document
|
46
|
+
|
47
|
+
a.show!
|
48
|
+
#==> sets the couch_visible property to true and saves the document
|
49
|
+
|
50
|
+
You can also ask whether the document is currently `hidden?` or `shown?`:
|
51
|
+
|
52
|
+
a = Article.first
|
53
|
+
a.hide!
|
54
|
+
a.shown? #==> false
|
55
|
+
a.hidden? #==> true
|
56
|
+
|
57
|
+
### Fetching Hidden/Shown documents
|
58
|
+
|
59
|
+
Lastly, when you mixed `CouchVisible` into your document, a new map/reduce was created for your document that allows you to easily find shown and hidden documents:
|
60
|
+
|
61
|
+
hidden_article = Article.create
|
62
|
+
hidden_article.hide!
|
63
|
+
|
64
|
+
Article.by_hidden
|
65
|
+
Article.count_hidden
|
66
|
+
Article.by_shown
|
67
|
+
Article.count_shown
|
68
|
+
|
69
|
+
You can use all of the typical options you would normally use in your `view_by`-created methods.
|
70
|
+
|
71
|
+
## CouchPublish / Memories Integration
|
72
|
+
|
73
|
+
The `couch_visible` integrates nicely with the `couch_publish` and `memories` gems for versioning / publishing. If you mix `Memories` or `CouchPublish` into your document, then mix `CouchVisible` into it, then `CouchVisible` will create an unversioned `couch_visible` property, so that reverting versions won't unintentionally toggle the visibility of the document.
|
74
|
+
|
75
|
+
For example, let's create a document with several versions, then inspect that state of `couch_visible` after reverting:
|
76
|
+
|
77
|
+
class Article < CouchRest::Model::Base
|
78
|
+
include Publish
|
79
|
+
include CouchVisible
|
80
|
+
|
81
|
+
property :title
|
82
|
+
end
|
83
|
+
|
84
|
+
a = Article.create :title => "The Mavs spank the Heat"
|
85
|
+
|
86
|
+
a.hidden?
|
87
|
+
#==> true
|
88
|
+
|
89
|
+
a.publish!
|
90
|
+
|
91
|
+
a.version
|
92
|
+
#==> 2
|
93
|
+
|
94
|
+
|
95
|
+
Our document is published, but hidden. Now let's unhide the document:
|
96
|
+
|
97
|
+
a.show!
|
98
|
+
|
99
|
+
a.version
|
100
|
+
#==> 3
|
101
|
+
|
102
|
+
Now the document is shown. Presumably, it would start showing up on the website.
|
103
|
+
|
104
|
+
Next, let's imagine our editor wanted to make the title more specific. You update the title and republish:
|
105
|
+
|
106
|
+
a.title
|
107
|
+
#==> "The spank the Heat in game 6"
|
108
|
+
|
109
|
+
a.publish!
|
110
|
+
|
111
|
+
The editor's boss wasn't happy with the change; they ask you to revert back to the old title. Here's where it gets interesting. If `memories` had versioned the `couch_visible` boolean property, then reverting back to version `2` would hide the document again. But since `CouchVisible` detected that you were using `Memories` or `CouchPublish`, it created the `couch_visible` property as a non-versioned property.
|
112
|
+
|
113
|
+
a.published_versions.first.publish!
|
114
|
+
|
115
|
+
a.hidden?
|
116
|
+
#==> false
|
117
|
+
|
118
|
+
So even though you've revert back to version 2, your document is still visible.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_visible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Parker
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-20 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -98,8 +98,29 @@ extensions: []
|
|
98
98
|
|
99
99
|
extra_rdoc_files: []
|
100
100
|
|
101
|
-
files:
|
102
|
-
|
101
|
+
files:
|
102
|
+
- lib/couch_visible.rb
|
103
|
+
- lib/couch_visible.rbc
|
104
|
+
- lib/couch_visible/config.rb
|
105
|
+
- lib/couch_visible/config.rbc
|
106
|
+
- lib/couch_visible/couch_visible.rb
|
107
|
+
- lib/couch_visible/couch_visible.rbc
|
108
|
+
- VERSION
|
109
|
+
- readme.markdown
|
110
|
+
- features/configuration.feature
|
111
|
+
- features/hide.feature
|
112
|
+
- features/memories_integration.feature
|
113
|
+
- features/show.feature
|
114
|
+
- features/step_definitions/configuration_steps.rb
|
115
|
+
- features/step_definitions/configuration_steps.rbc
|
116
|
+
- features/step_definitions/hide_steps.rb
|
117
|
+
- features/step_definitions/hide_steps.rbc
|
118
|
+
- features/step_definitions/memories_integration_steps.rb
|
119
|
+
- features/step_definitions/memories_integration_steps.rbc
|
120
|
+
- features/step_definitions/show_steps.rb
|
121
|
+
- features/step_definitions/show_steps.rbc
|
122
|
+
- features/support/env.rb
|
123
|
+
- features/support/env.rbc
|
103
124
|
has_rdoc: true
|
104
125
|
homepage: http://github.com/moonmaster9000/couch_visible
|
105
126
|
licenses: []
|
@@ -134,5 +155,18 @@ rubygems_version: 1.5.2
|
|
134
155
|
signing_key:
|
135
156
|
specification_version: 3
|
136
157
|
summary: Is a document visible?
|
137
|
-
test_files:
|
138
|
-
|
158
|
+
test_files:
|
159
|
+
- features/configuration.feature
|
160
|
+
- features/hide.feature
|
161
|
+
- features/memories_integration.feature
|
162
|
+
- features/show.feature
|
163
|
+
- features/step_definitions/configuration_steps.rb
|
164
|
+
- features/step_definitions/configuration_steps.rbc
|
165
|
+
- features/step_definitions/hide_steps.rb
|
166
|
+
- features/step_definitions/hide_steps.rbc
|
167
|
+
- features/step_definitions/memories_integration_steps.rb
|
168
|
+
- features/step_definitions/memories_integration_steps.rbc
|
169
|
+
- features/step_definitions/show_steps.rb
|
170
|
+
- features/step_definitions/show_steps.rbc
|
171
|
+
- features/support/env.rb
|
172
|
+
- features/support/env.rbc
|