stringex 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/README.rdoc +7 -1
- data/VERSION +1 -1
- data/lib/stringex/acts_as_url/adapter/base.rb +7 -0
- data/lib/stringex/configuration/acts_as_url.rb +6 -2
- data/stringex.gemspec +2 -2
- data/test/unit/acts_as_url_integration_test.rb +32 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
NjA4ZGNmOGZiZGNiY2VkNTIwYTg2NGY1MjVmNGIwN2NmZDRhNTRkNg==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
NDQ5NTlmMTU2MTgxYTA1OTRkMmRmMGE5YTllOTI1NGQwMDNiODYyYw==
|
|
7
7
|
!binary "U0hBNTEy":
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
YjNjMDc2N2QxODJhODJhZWVlNDBiMjkwODBhNWMwODlhNTEwODM4ODVlMWEy
|
|
10
|
+
MGI4OTU4NzhiY2EyYTM3OTE4Y2E5YzQwZTFmYzc5NGE1Nzk0YzYxYmFjOGIw
|
|
11
|
+
Y2NlODI0Njg2NzQ3NWUzZGNiYWQwN2EzOGI5ZDc3Y2UxODk3MzE=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
NTUxYjg0NDExOTk5OTk4OGE0NmZmZmE4NDY0OTM1MDkzYjZlMWUwOTY1Njhl
|
|
14
|
+
ZGI1M2QxM2I0MDAwMzdlNzNhNjJiNjY4NGNiNGNmZTc2MGNhZGI5Y2E3NTIz
|
|
15
|
+
NTVjZGM3MzUwOTU1MmZkYWFlNTIwOWY1MDg5MmZkNDM2MTc0YzE=
|
data/README.rdoc
CHANGED
|
@@ -13,7 +13,8 @@ This library is designed to create URI-friendly representations of an attribute,
|
|
|
13
13
|
# Inside your model
|
|
14
14
|
acts_as_url :title
|
|
15
15
|
|
|
16
|
-
which will populate the <tt>url</tt> attribute on the object with the converted contents of the <tt>title</tt> attribute.
|
|
16
|
+
which will populate the <tt>url</tt> attribute on the object with the converted contents of the <tt>title</tt> attribute.
|
|
17
|
+
<tt>acts_as_url</tt> takes the following options:
|
|
17
18
|
|
|
18
19
|
<tt>:url_attribute</tt>:: The name of the attribute to use for storing the generated url string.
|
|
19
20
|
Default is <tt>:url</tt>
|
|
@@ -30,6 +31,11 @@ which will populate the <tt>url</tt> attribute on the object with the converted
|
|
|
30
31
|
<tt>:limit</tt>:: If set, will limit length of url generated. Default is nil.
|
|
31
32
|
<tt>:truncate_words</tt>:: Used with :limit. If set to false, the url will be truncated to the last
|
|
32
33
|
whole word before the limit was reached. Default is true.
|
|
34
|
+
<tt>:blacklist</tt>:: List of urls that should not be allowed. Default is <tt>%w{new}</tt> [which avoids confusion
|
|
35
|
+
on urls like <tt>/documents/new</tt>].
|
|
36
|
+
<tt>:blacklist_policy</tt>:: Proc or lambda defining new naming behavior when blacklisted urls are encountered.
|
|
37
|
+
Default converts <tt>/documents/new</tt> to </tt>/documents/new-document</tt>.
|
|
38
|
+
|
|
33
39
|
|
|
34
40
|
In order to use the generated url attribute, you will probably want to override <tt>to_param</tt> like so, in your Model:
|
|
35
41
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.
|
|
1
|
+
2.3.0
|
|
@@ -22,6 +22,7 @@ module Stringex
|
|
|
22
22
|
self.instance = instance
|
|
23
23
|
|
|
24
24
|
handle_url!
|
|
25
|
+
handle_blacklisted_url!
|
|
25
26
|
handle_duplicate_url! unless settings.allow_duplicates
|
|
26
27
|
end
|
|
27
28
|
|
|
@@ -132,6 +133,12 @@ module Stringex
|
|
|
132
133
|
write_url_attribute base_url
|
|
133
134
|
end
|
|
134
135
|
|
|
136
|
+
def handle_blacklisted_url!
|
|
137
|
+
return unless settings.blacklist.to_set.include?(base_url)
|
|
138
|
+
self.base_url = settings.blacklist_policy.call(instance, base_url)
|
|
139
|
+
write_url_attribute base_url
|
|
140
|
+
end
|
|
141
|
+
|
|
135
142
|
def instance_from_db
|
|
136
143
|
instance.class.find(instance.id)
|
|
137
144
|
end
|
|
@@ -15,7 +15,7 @@ module Stringex
|
|
|
15
15
|
:force_downcase,
|
|
16
16
|
:limit,
|
|
17
17
|
:replace_whitespace_with,
|
|
18
|
-
:truncate_words
|
|
18
|
+
:truncate_words
|
|
19
19
|
].inject(Hash.new){|m, x| m[x] = settings.send(x); m}
|
|
20
20
|
end
|
|
21
21
|
|
|
@@ -39,8 +39,12 @@ module Stringex
|
|
|
39
39
|
:scope_for_url => nil,
|
|
40
40
|
:sync_url => false,
|
|
41
41
|
:url_attribute => "url",
|
|
42
|
+
:blacklist => %w[new],
|
|
43
|
+
:blacklist_policy => lambda { |instance, url|
|
|
44
|
+
"#{url}-#{instance.class.to_s.downcase}"
|
|
45
|
+
}
|
|
42
46
|
}.merge(Stringex::Configuration::StringExtensions.new.default_settings)
|
|
43
47
|
end
|
|
44
48
|
end
|
|
45
49
|
end
|
|
46
|
-
end
|
|
50
|
+
end
|
data/stringex.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "stringex"
|
|
8
|
-
s.version = "2.
|
|
8
|
+
s.version = "2.3.0"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Russell Norris"]
|
|
12
|
-
s.date = "2014-03-
|
|
12
|
+
s.date = "2014-03-11"
|
|
13
13
|
s.description = "Some [hopefully] useful extensions to Ruby's String class. Stringex is made up of three libraries: ActsAsUrl [permalink solution with better character translation], Unidecoder [Unicode to ASCII transliteration], and StringExtensions [miscellaneous helper methods for the String class]."
|
|
14
14
|
s.email = "rsl@luckysneaks.com"
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -20,6 +20,38 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
|
20
20
|
assert_equal "unique-1", @other_doc.url
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
def test_should_avoid_blacklist
|
|
24
|
+
@doc = Document.create(:title => "New")
|
|
25
|
+
@other_doc = Document.create(:title => "new")
|
|
26
|
+
assert_equal "new-document", @doc.url
|
|
27
|
+
assert_equal "new-document-1", @other_doc.url
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_should_allow_customizing_blacklist
|
|
31
|
+
Document.class_eval do
|
|
32
|
+
# Un-blacklisting 'new' isn't advisable
|
|
33
|
+
acts_as_url :title, :blacklist => %w{special}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
@doc = Document.create(:title => "New")
|
|
37
|
+
@other_doc = Document.create(:title => "Special")
|
|
38
|
+
assert_equal 'new', @doc.url
|
|
39
|
+
assert_equal 'special-document', @other_doc.url
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_should_allow_customizing_blacklist_policy
|
|
43
|
+
Document.class_eval do
|
|
44
|
+
acts_as_url :title, :blacklist_policy => Proc.new(){|instance, url|
|
|
45
|
+
"#{url}-customized"
|
|
46
|
+
}
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
@doc = Document.create(:title => "New")
|
|
50
|
+
@other_doc = Document.create(:title => "New")
|
|
51
|
+
assert_equal 'new-customized', @doc.url
|
|
52
|
+
assert_equal 'new-customized-1', @other_doc.url
|
|
53
|
+
end
|
|
54
|
+
|
|
23
55
|
def test_should_create_unique_url_when_partial_url_already_exists
|
|
24
56
|
@doc = Document.create(:title => "House Farms")
|
|
25
57
|
@other_doc = Document.create(:title => "House Farm")
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stringex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Russell Norris
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-03-
|
|
11
|
+
date: 2014-03-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: jeweler
|