couch_visible 0.0.2 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/features/couch_publish_integration.feature +39 -0
- data/features/hide.feature +3 -2
- data/features/show.feature +2 -2
- data/features/step_definitions/couch_publish_integration.rb +11 -0
- data/features/step_definitions/couch_publish_integration.rbc +328 -0
- data/features/step_definitions/hide_steps.rb +4 -4
- data/features/step_definitions/hide_steps.rbc +24 -45
- data/features/step_definitions/show_steps.rb +4 -4
- data/features/step_definitions/show_steps.rbc +18 -39
- data/features/support/env.rb +7 -1
- data/lib/couch_visible.rb +6 -0
- data/lib/couch_visible.rbc +54 -6
- data/lib/couch_visible/conditions/published.rb +9 -0
- data/lib/couch_visible/conditions/unpublished.rb +9 -0
- data/lib/couch_visible/couch_visible.rb +13 -14
- data/lib/couch_visible/couch_visible.rbc +236 -218
- data/lib/couch_visible/integrations/couch_publish.rb +15 -0
- data/lib/couch_visible/maps/by_hidden.rb +16 -0
- data/lib/couch_visible/maps/by_hidden.rbc +305 -0
- data/lib/couch_visible/maps/by_shown.rb +15 -0
- data/lib/couch_visible/maps/by_shown.rbc +305 -0
- data/readme.markdown +93 -56
- metadata +38 -11
data/readme.markdown
CHANGED
@@ -9,64 +9,77 @@ It's a gem. Either run `gem install couch_visible` at the command line, or add `
|
|
9
9
|
## Usage
|
10
10
|
|
11
11
|
The gem provides a mixin `CouchVisible` for your `CouchRest::Model::Base` derived documents:
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
class Article < CouchRest::Model::Base
|
15
|
+
include CouchVisible
|
16
|
+
end
|
17
|
+
```
|
16
18
|
|
17
19
|
### Hidden by default
|
18
20
|
|
19
21
|
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
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class Article < CouchRest::Model::Base
|
25
|
+
include CouchVisible
|
26
|
+
show_by_default!
|
27
|
+
end
|
28
|
+
```
|
25
29
|
|
26
30
|
You can also configure this globally:
|
27
31
|
|
28
|
-
|
32
|
+
```ruby
|
33
|
+
CouchVisible.show_by_default!
|
34
|
+
```
|
29
35
|
|
30
36
|
Now, all document models that include CouchVisible will be shown by default. They could override the global default by calling "hide_by_default!":
|
31
37
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
```ruby
|
39
|
+
class Post < CouchRest::Model::Base
|
40
|
+
include CouchVisible
|
41
|
+
hide_by_default!
|
42
|
+
end
|
43
|
+
```
|
37
44
|
|
38
45
|
### Showing and Hiding Documents
|
39
46
|
|
40
47
|
`CouchVisible` lets you toggle the visibility of documents via `show!` and `hide!` methods:
|
41
48
|
|
42
|
-
|
49
|
+
```ruby
|
50
|
+
a = Article.first
|
43
51
|
|
44
|
-
|
45
|
-
|
52
|
+
a.hide!
|
53
|
+
#==> sets the couch_visible property to false and saves the document
|
46
54
|
|
47
|
-
|
48
|
-
|
55
|
+
a.show!
|
56
|
+
#==> sets the couch_visible property to true and saves the document
|
57
|
+
```
|
49
58
|
|
50
59
|
You can also ask whether the document is currently `hidden?` or `shown?`:
|
51
60
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
61
|
+
```ruby
|
62
|
+
a = Article.first
|
63
|
+
a.hide!
|
64
|
+
a.shown? #==> false
|
65
|
+
a.hidden? #==> true
|
66
|
+
```
|
56
67
|
|
57
68
|
### Fetching Hidden/Shown documents
|
58
69
|
|
59
70
|
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
71
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
Article.by_hidden
|
65
|
-
Article.count_hidden
|
66
|
-
Article.by_shown
|
67
|
-
Article.count_shown
|
72
|
+
```ruby
|
73
|
+
hidden_article = Article.create
|
74
|
+
hidden_article.hide!
|
68
75
|
|
69
|
-
|
76
|
+
Article.map_by_hidden.get!
|
77
|
+
Article.count_by_hidden.get!
|
78
|
+
Article.map_by_shown.get!
|
79
|
+
Article.count_by_shown.get!
|
80
|
+
```
|
81
|
+
|
82
|
+
You can use all of the typical CouchDB options you would normally use in your queries. If you're unfamiliar with this format, checkout the `couch_view` gem, which `couch_visible` depends on: http://github.com/moonmaster9000/couch_view
|
70
83
|
|
71
84
|
## CouchPublish / Memories Integration
|
72
85
|
|
@@ -74,45 +87,69 @@ The `couch_visible` integrates nicely with the `couch_publish` and `memories` ge
|
|
74
87
|
|
75
88
|
For example, let's create a document with several versions, then inspect that state of `couch_visible` after reverting:
|
76
89
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
90
|
+
```ruby
|
91
|
+
class Article < CouchRest::Model::Base
|
92
|
+
include Publish
|
93
|
+
include CouchVisible
|
94
|
+
|
95
|
+
property :title
|
96
|
+
end
|
83
97
|
|
84
|
-
|
85
|
-
|
86
|
-
a.hidden?
|
87
|
-
#==> true
|
98
|
+
a = Article.create :title => "The Mavs spank the Heat"
|
88
99
|
|
89
|
-
|
100
|
+
a.hidden?
|
101
|
+
#==> true
|
90
102
|
|
91
|
-
|
92
|
-
#==> 2
|
103
|
+
a.publish!
|
93
104
|
|
105
|
+
a.version
|
106
|
+
#==> 2
|
107
|
+
```
|
94
108
|
|
95
109
|
Our document is published, but hidden. Now let's unhide the document:
|
96
110
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
111
|
+
```ruby
|
112
|
+
a.show!
|
113
|
+
|
114
|
+
a.version
|
115
|
+
#==> 3
|
116
|
+
```
|
101
117
|
|
102
118
|
Now the document is shown. Presumably, it would start showing up on the website.
|
103
119
|
|
104
120
|
Next, let's imagine our editor wanted to make the title more specific. You update the title and republish:
|
105
121
|
|
106
|
-
|
107
|
-
|
122
|
+
```ruby
|
123
|
+
a.title
|
124
|
+
#==> "The spank the Heat in game 6"
|
108
125
|
|
109
|
-
|
126
|
+
a.publish!
|
127
|
+
```
|
110
128
|
|
111
129
|
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
130
|
|
113
|
-
|
131
|
+
```ruby
|
132
|
+
a.published_versions.first.publish!
|
133
|
+
|
134
|
+
a.hidden?
|
135
|
+
#==> false
|
136
|
+
```
|
137
|
+
|
138
|
+
So even though you've reverted back to version 2, your document is still visible.
|
139
|
+
|
140
|
+
### Filtering your views by published and unpublished
|
141
|
+
|
142
|
+
Another nice integration: when you include `CouchVisible` into a model that already includes `CouchPublish`, you'll be able to filter your `map_by_hidden`/`count_by_hidden`/`map_by_shown`/`count_by_shown` queries for `published` and `unpublished` documents:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
class Article < CouchRest::Model::Base
|
146
|
+
include CouchPublish
|
147
|
+
include CouchVisible
|
148
|
+
end
|
114
149
|
|
115
|
-
|
116
|
-
|
150
|
+
Article.map_by_shown.published.get!
|
151
|
+
#==> all of the shown and published Article documents
|
117
152
|
|
118
|
-
|
153
|
+
Article.count_by_hidden.unpublished.get!
|
154
|
+
#==> all of the hidden documents that have never been published
|
155
|
+
```
|
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: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Parker
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
19
|
-
default_executable:
|
18
|
+
date: 2011-08-25 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: cucumber
|
@@ -61,7 +60,7 @@ dependencies:
|
|
61
60
|
type: :development
|
62
61
|
version_requirements: *id003
|
63
62
|
- !ruby/object:Gem::Dependency
|
64
|
-
name:
|
63
|
+
name: couch_publish
|
65
64
|
prerelease: false
|
66
65
|
requirement: &id004 !ruby/object:Gem::Requirement
|
67
66
|
none: false
|
@@ -90,6 +89,22 @@ dependencies:
|
|
90
89
|
version: 1.0.0
|
91
90
|
type: :runtime
|
92
91
|
version_requirements: *id005
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: couch_view
|
94
|
+
prerelease: false
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 25
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
- 1
|
104
|
+
- 1
|
105
|
+
version: 0.1.1
|
106
|
+
type: :runtime
|
107
|
+
version_requirements: *id006
|
93
108
|
description: Specify whether or not a document is visible.
|
94
109
|
email: moonmaster9000@gmail.com
|
95
110
|
executables: []
|
@@ -99,20 +114,30 @@ extensions: []
|
|
99
114
|
extra_rdoc_files: []
|
100
115
|
|
101
116
|
files:
|
102
|
-
- lib/couch_visible.rb
|
103
|
-
- lib/couch_visible.
|
117
|
+
- lib/couch_visible/conditions/published.rb
|
118
|
+
- lib/couch_visible/conditions/unpublished.rb
|
104
119
|
- lib/couch_visible/config.rb
|
105
120
|
- lib/couch_visible/config.rbc
|
106
121
|
- lib/couch_visible/couch_visible.rb
|
107
122
|
- lib/couch_visible/couch_visible.rbc
|
123
|
+
- lib/couch_visible/integrations/couch_publish.rb
|
124
|
+
- lib/couch_visible/maps/by_hidden.rb
|
125
|
+
- lib/couch_visible/maps/by_hidden.rbc
|
126
|
+
- lib/couch_visible/maps/by_shown.rb
|
127
|
+
- lib/couch_visible/maps/by_shown.rbc
|
128
|
+
- lib/couch_visible.rb
|
129
|
+
- lib/couch_visible.rbc
|
108
130
|
- VERSION
|
109
131
|
- readme.markdown
|
110
132
|
- features/configuration.feature
|
133
|
+
- features/couch_publish_integration.feature
|
111
134
|
- features/hide.feature
|
112
135
|
- features/memories_integration.feature
|
113
136
|
- features/show.feature
|
114
137
|
- features/step_definitions/configuration_steps.rb
|
115
138
|
- features/step_definitions/configuration_steps.rbc
|
139
|
+
- features/step_definitions/couch_publish_integration.rb
|
140
|
+
- features/step_definitions/couch_publish_integration.rbc
|
116
141
|
- features/step_definitions/hide_steps.rb
|
117
142
|
- features/step_definitions/hide_steps.rbc
|
118
143
|
- features/step_definitions/memories_integration_steps.rb
|
@@ -121,7 +146,6 @@ files:
|
|
121
146
|
- features/step_definitions/show_steps.rbc
|
122
147
|
- features/support/env.rb
|
123
148
|
- features/support/env.rbc
|
124
|
-
has_rdoc: true
|
125
149
|
homepage: http://github.com/moonmaster9000/couch_visible
|
126
150
|
licenses: []
|
127
151
|
|
@@ -151,17 +175,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
175
|
requirements: []
|
152
176
|
|
153
177
|
rubyforge_project:
|
154
|
-
rubygems_version: 1.5
|
178
|
+
rubygems_version: 1.8.5
|
155
179
|
signing_key:
|
156
180
|
specification_version: 3
|
157
181
|
summary: Is a document visible?
|
158
182
|
test_files:
|
159
183
|
- features/configuration.feature
|
184
|
+
- features/couch_publish_integration.feature
|
160
185
|
- features/hide.feature
|
161
186
|
- features/memories_integration.feature
|
162
187
|
- features/show.feature
|
163
188
|
- features/step_definitions/configuration_steps.rb
|
164
189
|
- features/step_definitions/configuration_steps.rbc
|
190
|
+
- features/step_definitions/couch_publish_integration.rb
|
191
|
+
- features/step_definitions/couch_publish_integration.rbc
|
165
192
|
- features/step_definitions/hide_steps.rb
|
166
193
|
- features/step_definitions/hide_steps.rbc
|
167
194
|
- features/step_definitions/memories_integration_steps.rb
|