mm-learnup-sluggable 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/lib/mm-learnup-sluggable.rb +32 -25
- metadata +4 -13
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZGU1ZjZmMmQ1Mzc2NzY5NWU2MTQwNjdiMGNmMTEzYjUxZWEzNTZlMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MGQzZjE4YzJlYTAxZDNlNGNkM2E4NzgwNzkyYTQ4MTc1ZTBiZDczYg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MzhmNjllYTNhNGNmMTA2MTU3NDhiMzBiZmVhNjNmYjM0MzY0MzA2MGEwZTZj
|
10
|
+
NjU2NTM0NDI1MDIwNWQ4YTZkZDY1NzRlYjNhOTE5M2JhMzc4OTNiNjZkZDQ5
|
11
|
+
NGE1YzdlMmM2NjYxNmQxMjhkOTBhMTgyNzNkNjBkN2Y3ODRlZmM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
M2MzOWZjNjQ0M2VkZjBkNzgzZmNiMjZkMDNiMmQ5OWQyMGJjYmUyZjliODUy
|
14
|
+
YWIwYzUwMjhiZmQ3Y2ViMWVjM2QyMTYzYzQyNmI1MjYwNWUwMzlkNzRhZDE1
|
15
|
+
MWJhOWI3NWVkNzgyZDI5ZjM3NjY3YTE2OGYxNWUzNjcyNGRlYzc=
|
data/lib/mm-learnup-sluggable.rb
CHANGED
@@ -12,6 +12,34 @@ module MongoMapper
|
|
12
12
|
end
|
13
13
|
|
14
14
|
module ClassMethods
|
15
|
+
def old_slug_exception(slug, obj)
|
16
|
+
error = MongoMapper::Plugins::LearnupSluggable::OldSlugException.new
|
17
|
+
error.old_slug = slug
|
18
|
+
error.new_slug = obj.slug
|
19
|
+
error.object = obj
|
20
|
+
error
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_by_slug!(slug)
|
24
|
+
if obj = find_by_slug(slug)
|
25
|
+
obj
|
26
|
+
else
|
27
|
+
raise MongoMapper::DocumentNotFound, "Couldn't find #{self} with slug: #{slug}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def find_by_slug_or_id(slug_or_id)
|
32
|
+
self.find_by_slug(slug_or_id) || self.find_by_id(slug_or_id)
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_by_slug_or_id!(slug_or_id)
|
36
|
+
if obj = find_by_slug_or_id(slug_or_id)
|
37
|
+
obj
|
38
|
+
else
|
39
|
+
raise MongoMapper::DocumentNotFound, "Couldn't find #{self} with slug or id: #{slug_or_id}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
15
43
|
def sluggable(to_slug = :title, options = {})
|
16
44
|
class_attribute :slug_options
|
17
45
|
|
@@ -22,7 +50,7 @@ module MongoMapper
|
|
22
50
|
:scope => nil,
|
23
51
|
:max_length => 256,
|
24
52
|
:start => 2,
|
25
|
-
:callback => [:before_validation, {:on => :create}]
|
53
|
+
:callback => [:before_validation, {:on => :create, :unless => :slug_field_changed?}]
|
26
54
|
}.merge(options)
|
27
55
|
|
28
56
|
key slug_options[:key], String
|
@@ -121,34 +149,13 @@ module MongoMapper
|
|
121
149
|
|
122
150
|
self.send(:"#{options[:key]}=", the_slug)
|
123
151
|
end
|
124
|
-
end
|
125
152
|
|
126
|
-
|
127
|
-
error = MongoMapper::Plugins::LearnupSluggable::OldSlugException.new
|
128
|
-
error.old_slug = slug
|
129
|
-
error.new_slug = obj.slug
|
130
|
-
error.object = obj
|
131
|
-
error
|
132
|
-
end
|
153
|
+
private
|
133
154
|
|
134
|
-
|
135
|
-
|
136
|
-
obj
|
137
|
-
else
|
138
|
-
raise MongoMapper::DocumentNotFound, "Couldn't find #{self} with slug: #{slug}"
|
155
|
+
def slug_field_changed?
|
156
|
+
self.send("#{self.class.slug_options[:key]}_changed?")
|
139
157
|
end
|
140
158
|
end
|
141
159
|
|
142
|
-
def find_by_slug_or_id(slug_or_id)
|
143
|
-
self.find_by_slug(slug_or_id) || self.find_by_id(slug_or_id)
|
144
|
-
end
|
145
|
-
|
146
|
-
def find_by_slug_or_id!(slug_or_id)
|
147
|
-
if obj = find_by_slug_or_id(slug_or_id)
|
148
|
-
obj
|
149
|
-
else
|
150
|
-
raise MongoMapper::DocumentNotFound, "Couldn't find #{self} with slug or id: #{slug_or_id}"
|
151
|
-
end
|
152
|
-
end
|
153
160
|
end
|
154
161
|
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mm-learnup-sluggable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Scott Taylor
|
@@ -14,7 +13,6 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: mongo_mapper
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ! '>='
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ! '>='
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,7 +27,6 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
31
|
- - ! '>='
|
36
32
|
- !ruby/object:Gem::Version
|
@@ -38,7 +34,6 @@ dependencies:
|
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
38
|
- - ! '>='
|
44
39
|
- !ruby/object:Gem::Version
|
@@ -51,11 +46,12 @@ extra_rdoc_files:
|
|
51
46
|
- README.rdoc
|
52
47
|
files:
|
53
48
|
- LICENSE
|
54
|
-
- Rakefile
|
55
49
|
- README.rdoc
|
50
|
+
- Rakefile
|
56
51
|
- lib/mm-learnup-sluggable.rb
|
57
52
|
homepage: http://github.com/GoLearnup/mm-learnup-sluggable
|
58
53
|
licenses: []
|
54
|
+
metadata: {}
|
59
55
|
post_install_message:
|
60
56
|
rdoc_options:
|
61
57
|
- --main
|
@@ -63,23 +59,18 @@ rdoc_options:
|
|
63
59
|
require_paths:
|
64
60
|
- lib
|
65
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
62
|
requirements:
|
68
63
|
- - ! '>='
|
69
64
|
- !ruby/object:Gem::Version
|
70
65
|
version: '0'
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
hash: -3827616878293107098
|
74
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
67
|
requirements:
|
77
68
|
- - ! '>='
|
78
69
|
- !ruby/object:Gem::Version
|
79
70
|
version: '0'
|
80
71
|
requirements: []
|
81
72
|
rubyforge_project:
|
82
|
-
rubygems_version:
|
73
|
+
rubygems_version: 2.2.2
|
83
74
|
signing_key:
|
84
75
|
specification_version: 3
|
85
76
|
summary: MongoMapper plugin to cache a slugged version of a field. Originally forked
|