mm-learnup-sluggable 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/Rakefile +1 -1
  3. data/lib/mm-learnup-sluggable.rb +13 -11
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTg1OTNkZjgzYjg5MmM4NGI3YmM2OTc3ZmJiYzA2ZWQ5NTljZWRkNw==
4
+ ZmU0N2FiYjAzNGYwNTg3OGNkOTI0ZGZlNTk4OWMwNzM3MzIzZTlkMQ==
5
5
  data.tar.gz: !binary |-
6
- Y2YzNzVkMDRkMDQxZGYyM2I2NWU2MWZjMWNkYmVhNDRkODFlYzljZA==
6
+ YzYxMzg4OTFiZmE1NTQwNmNiOWI3NWIzOTZkYzAxYmM3YTNhNGY2NQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- OGFlOTc0MDg5YWYyYTJmMWFlNzVhNWUwZTFiMDU3ODQ4ZWQ4Mjk5YzQ2Yjcx
10
- ZGE5NWY3Y2U1MjA3ZDRlOGMxNGMyOTg3ZGIxYjI2Zjg1ZTQ0MzFjNGU1NWZl
11
- NGQ0Mzc0MjQ2M2VhODQ0ZTQ0ZTAxOTFhZTRkMzEyODcxYTA2YjI=
9
+ MTc4NGYxMDBhOGQ1MjdlNGQzOWZkMWQyOTEyNGY2NmUyYjkyMzA4YmM1OTRk
10
+ NDRjZWZlODljNWZlNzllNDA0NDk2MjMzMjBjNDhiOTZjNmNlZjI1Yzg1ZTE2
11
+ MjBkYmQwNGM4MGM4YTUyZGU2NzQ4MGI4MmUwYjZjOTNlNzdiMWY=
12
12
  data.tar.gz: !binary |-
13
- YTBlOGM0MzAzNzdjZDkzMTAwYjQxZGVhNmE1ODFkNDc2ZmFjNTY1ODFiZDFk
14
- OGVjNTJiMmU1ZTVlYzljMjdlYjhmMTc0ZmVjMWFmOTAwNWJmMmQ4ZDlkM2Uy
15
- ZjMwNzZiMGJlYWI0MGJkZTg5MjkzNTI2MjQzMDg5NTgzOWY5OTA=
13
+ NzlkOTY1MTVhNjI0ZmZhMzNkMDZlZmRkZDhhOGY3ZTU0ZmE4ZmY0YWEyMTEw
14
+ NWJjZDE1MGZhYjAwOGEyOTUyMDA5NDBiMGRlMWYyOWQxYmUxOGUxYTNlNzNj
15
+ NzYxNzBmNzVjYTQ0N2Y3YWMyYjdjNjAxOGI4ZjMyNTcxYjU0NzM=
data/Rakefile CHANGED
@@ -19,7 +19,7 @@ spec = Gem::Specification.new do |s|
19
19
 
20
20
  # Change these as appropriate
21
21
  s.name = "mm-learnup-sluggable"
22
- s.version = "0.3.5"
22
+ s.version = "0.3.6"
23
23
  s.summary = "MongoMapper plugin to cache a slugged version of a field. Originally forked from mm-learnup-sluggable."
24
24
  s.author = "Scott Taylor"
25
25
  s.email = "scott@railsnewbie.com"
@@ -20,16 +20,6 @@ module MongoMapper
20
20
  error
21
21
  end
22
22
 
23
- def find_by_slug(slug)
24
- if obj = where(@_slug_key => slug).first
25
- obj
26
- elsif obj = where(:old_slugs => slug).first
27
- raise old_slug_exception(slug, obj)
28
- else
29
- nil
30
- end
31
- end
32
-
33
23
  def find_by_slug!(slug)
34
24
  if obj = find_by_slug(slug)
35
25
  obj
@@ -71,7 +61,6 @@ module MongoMapper
71
61
  self.send(slug_options[:callback], :set_slug)
72
62
 
73
63
  slug_key = self.slug_options[:key]
74
- @_slug_key = slug_key
75
64
 
76
65
  define_method :to_param do
77
66
  self.send(slug_key).blank? ? self.id.to_s : self.send(slug_key)
@@ -97,6 +86,19 @@ module MongoMapper
97
86
  # value.respond_to?(:downcase) ? value.downcase : value
98
87
  # end
99
88
 
89
+ metaclass = class << self; self; end
90
+ metaclass.class_eval do
91
+ define_method :find_by_slug do |slug|
92
+ if obj = where(slug_key => slug).first
93
+ obj
94
+ elsif obj = where(:old_slugs => slug).first
95
+ raise old_slug_exception(slug, obj)
96
+ else
97
+ nil
98
+ end
99
+ end
100
+ end
101
+
100
102
  before_update do
101
103
  if self.send("#{slug_key}_changed?")
102
104
  self.old_slugs = self.old_slugs.reject { |slug| slug == self.send(slug_key) }
metadata CHANGED
@@ -1,7 +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
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Taylor
@@ -70,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 2.4.5
73
+ rubygems_version: 2.4.6
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: MongoMapper plugin to cache a slugged version of a field. Originally forked