mongoid_slug 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -3
- data/lib/mongoid/slug.rb +16 -3
- data/lib/mongoid/slug/version.rb +1 -1
- data/spec/mongoid/slug_spec.rb +26 -0
- metadata +20 -13
data/README.md
CHANGED
@@ -42,7 +42,7 @@ Finder
|
|
42
42
|
|
43
43
|
In your controller, throw in some minimal magic:
|
44
44
|
|
45
|
-
# GET /books/a-thousand-plateaus/authors/
|
45
|
+
# GET /books/a-thousand-plateaus/authors/gilles-deleuze
|
46
46
|
author = Book.find_by_slug(params[:book_id]).
|
47
47
|
authors.
|
48
48
|
find_by_name(params[:id])
|
@@ -66,8 +66,6 @@ defining the slug.
|
|
66
66
|
Scope
|
67
67
|
-----
|
68
68
|
|
69
|
-
Embedded objects that are automatically scoped by their parent.
|
70
|
-
|
71
69
|
To scope an object by a reference association, pass `:scope`:
|
72
70
|
|
73
71
|
class Company
|
@@ -89,6 +87,8 @@ any company, the scope will fall back to the root employees collection.
|
|
89
87
|
Currently, if you have an irregular association name, you **must**
|
90
88
|
specify the `:inverse_of` option on the other side of the assocation.
|
91
89
|
|
90
|
+
Embedded objects are automatically scoped by their parent.
|
91
|
+
|
92
92
|
Indexes
|
93
93
|
-------
|
94
94
|
|
data/lib/mongoid/slug.rb
CHANGED
@@ -57,6 +57,17 @@ module Mongoid #:nodoc:
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
# Regenerates slug.
|
61
|
+
#
|
62
|
+
# This method should come in handy when generating slugs for an existing
|
63
|
+
# collection.
|
64
|
+
def slug!
|
65
|
+
return if new_record?
|
66
|
+
|
67
|
+
self.send(:generate_slug!)
|
68
|
+
save if self.send("#{self.slug_name}_changed?")
|
69
|
+
end
|
70
|
+
|
60
71
|
def to_param
|
61
72
|
self.send(slug_name)
|
62
73
|
end
|
@@ -79,10 +90,12 @@ module Mongoid #:nodoc:
|
|
79
90
|
end
|
80
91
|
end
|
81
92
|
|
93
|
+
def generate_slug!
|
94
|
+
self.send("#{slug_name}=", find_unique_slug)
|
95
|
+
end
|
96
|
+
|
82
97
|
def generate_slug
|
83
|
-
if new_record? || slugged_fields_changed?
|
84
|
-
self.send("#{slug_name}=", find_unique_slug)
|
85
|
-
end
|
98
|
+
generate_slug! if new_record? || slugged_fields_changed?
|
86
99
|
end
|
87
100
|
|
88
101
|
def increment_slug_counter
|
data/lib/mongoid/slug/version.rb
CHANGED
data/spec/mongoid/slug_spec.rb
CHANGED
@@ -293,5 +293,31 @@ module Mongoid
|
|
293
293
|
comic_book.slug.should_not eql(book.title)
|
294
294
|
end
|
295
295
|
end
|
296
|
+
|
297
|
+
describe "#slug!" do
|
298
|
+
before do
|
299
|
+
class Foo
|
300
|
+
include Mongoid::Document
|
301
|
+
field :name
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
let!(:foo) do
|
306
|
+
Foo.create(:name => "John")
|
307
|
+
end
|
308
|
+
|
309
|
+
it "regenerates slug" do
|
310
|
+
class Foo
|
311
|
+
include Mongoid::Slug
|
312
|
+
slug :name
|
313
|
+
end
|
314
|
+
|
315
|
+
foo.reload.slug.should be_nil
|
316
|
+
|
317
|
+
foo.slug!
|
318
|
+
|
319
|
+
foo.reload.slug.should eql 'john'
|
320
|
+
end
|
321
|
+
end
|
296
322
|
end
|
297
323
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid_slug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 5
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
8
|
+
- 2
|
9
|
+
version: 0.6.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Paper Cavalier
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-02-03 00:00:00 +00:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,14 +25,13 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 15424089
|
30
28
|
segments:
|
31
29
|
- 2
|
32
30
|
- 0
|
33
31
|
- 0
|
34
32
|
- rc
|
35
|
-
-
|
36
|
-
version: 2.0.0.rc.
|
33
|
+
- 7
|
34
|
+
version: 2.0.0.rc.7
|
37
35
|
type: :runtime
|
38
36
|
version_requirements: *id001
|
39
37
|
- !ruby/object:Gem::Dependency
|
@@ -44,7 +42,6 @@ dependencies:
|
|
44
42
|
requirements:
|
45
43
|
- - ~>
|
46
44
|
- !ruby/object:Gem::Version
|
47
|
-
hash: 31
|
48
45
|
segments:
|
49
46
|
- 1
|
50
47
|
- 2
|
@@ -60,7 +57,6 @@ dependencies:
|
|
60
57
|
requirements:
|
61
58
|
- - ~>
|
62
59
|
- !ruby/object:Gem::Version
|
63
|
-
hash: 31
|
64
60
|
segments:
|
65
61
|
- 1
|
66
62
|
- 2
|
@@ -76,7 +72,6 @@ dependencies:
|
|
76
72
|
requirements:
|
77
73
|
- - ~>
|
78
74
|
- !ruby/object:Gem::Version
|
79
|
-
hash: 7
|
80
75
|
segments:
|
81
76
|
- 0
|
82
77
|
- 6
|
@@ -92,7 +87,6 @@ dependencies:
|
|
92
87
|
requirements:
|
93
88
|
- - ~>
|
94
89
|
- !ruby/object:Gem::Version
|
95
|
-
hash: 31
|
96
90
|
segments:
|
97
91
|
- 2
|
98
92
|
- 4
|
@@ -100,6 +94,21 @@ dependencies:
|
|
100
94
|
version: 2.4.0
|
101
95
|
type: :development
|
102
96
|
version_requirements: *id005
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ruby-debug19
|
99
|
+
prerelease: false
|
100
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ~>
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 0
|
107
|
+
- 11
|
108
|
+
- 0
|
109
|
+
version: 0.11.0
|
110
|
+
type: :development
|
111
|
+
version_requirements: *id006
|
103
112
|
description: Mongoid Slug generates a URL slug or permalink based on one or more fields in a Mongoid model.
|
104
113
|
email:
|
105
114
|
- code@papercavalier.com
|
@@ -137,7 +146,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
137
146
|
requirements:
|
138
147
|
- - ">="
|
139
148
|
- !ruby/object:Gem::Version
|
140
|
-
hash: 3
|
141
149
|
segments:
|
142
150
|
- 0
|
143
151
|
version: "0"
|
@@ -146,7 +154,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
154
|
requirements:
|
147
155
|
- - ">="
|
148
156
|
- !ruby/object:Gem::Version
|
149
|
-
hash: 3
|
150
157
|
segments:
|
151
158
|
- 0
|
152
159
|
version: "0"
|