smartname 0.3.1 → 0.4.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 +4 -4
- data/Gemfile +6 -6
- data/Gemfile.lock +52 -40
- data/VERSION +1 -1
- data/lib/smart_name.rb +19 -2
- data/spec/lib/smart_name_spec.rb +20 -0
- metadata +23 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 25ae787d7849fe77b765c1465ed2b1a534f8206a
|
|
4
|
+
data.tar.gz: c27cf085aecc946cb2a40fdd3fd1489a1c146efc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e72752157b7207b45fc2633311183a66522a9115c39618be0f5b309e86a333a1ce8c2aab2be7cfb7884384f61dfd4419547de8b8c0f9df619e5fedcf05407d75
|
|
7
|
+
data.tar.gz: db06e0e3472152b197177d663ee67132b29397b643beebaa6049470cf945908dd07da0f3bff3b7d9fa37c0b870551347ffb181c4c6ec538d718ef4f350417598
|
data/Gemfile
CHANGED
|
@@ -3,12 +3,12 @@ source "http://rubygems.org"
|
|
|
3
3
|
# Add dependencies to develop your gem here.
|
|
4
4
|
# Include everything needed to run rake, tests, features, etc.
|
|
5
5
|
group :development do
|
|
6
|
-
gem "rspec"
|
|
7
|
-
gem "rdoc"
|
|
8
|
-
gem "bundler"
|
|
9
|
-
gem "jeweler"
|
|
10
|
-
#gem "rcov"
|
|
6
|
+
gem "rspec"
|
|
7
|
+
gem "rdoc"
|
|
8
|
+
gem "bundler"
|
|
9
|
+
gem "jeweler"
|
|
10
|
+
#gem "rcov"
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
gem "activesupport"
|
|
14
|
-
gem 'htmlentities'
|
|
14
|
+
gem 'htmlentities'
|
data/Gemfile.lock
CHANGED
|
@@ -1,63 +1,75 @@
|
|
|
1
1
|
GEM
|
|
2
2
|
remote: http://rubygems.org/
|
|
3
3
|
specs:
|
|
4
|
-
activesupport (
|
|
4
|
+
activesupport (5.0.0.1)
|
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
5
6
|
i18n (~> 0.7)
|
|
6
|
-
json (~> 1.7, >= 1.7.7)
|
|
7
7
|
minitest (~> 5.1)
|
|
8
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
|
9
8
|
tzinfo (~> 1.1)
|
|
10
9
|
addressable (2.4.0)
|
|
11
10
|
builder (3.2.2)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
concurrent-ruby (1.0.2)
|
|
12
|
+
descendants_tracker (0.0.4)
|
|
13
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
|
14
|
+
diff-lcs (1.2.5)
|
|
15
|
+
faraday (0.9.2)
|
|
16
|
+
multipart-post (>= 1.2, < 3)
|
|
15
17
|
git (1.3.0)
|
|
16
|
-
github_api (0.
|
|
17
|
-
addressable
|
|
18
|
-
|
|
18
|
+
github_api (0.11.3)
|
|
19
|
+
addressable (~> 2.3)
|
|
20
|
+
descendants_tracker (~> 0.0.1)
|
|
21
|
+
faraday (~> 0.8, < 0.10)
|
|
19
22
|
hashie (>= 1.2)
|
|
20
|
-
multi_json (
|
|
21
|
-
nokogiri (~> 1.
|
|
23
|
+
multi_json (>= 1.7.5, < 2.0)
|
|
24
|
+
nokogiri (~> 1.6.0)
|
|
22
25
|
oauth2
|
|
23
|
-
hashie (3.4.
|
|
26
|
+
hashie (3.4.6)
|
|
24
27
|
highline (1.7.8)
|
|
25
28
|
htmlentities (4.3.4)
|
|
26
29
|
i18n (0.7.0)
|
|
27
|
-
jeweler (1.
|
|
30
|
+
jeweler (2.1.2)
|
|
28
31
|
builder
|
|
29
|
-
bundler (
|
|
32
|
+
bundler (>= 1.0)
|
|
30
33
|
git (>= 1.2.5)
|
|
31
|
-
github_api (
|
|
34
|
+
github_api (~> 0.11.0)
|
|
32
35
|
highline (>= 1.6.15)
|
|
33
|
-
nokogiri (
|
|
36
|
+
nokogiri (>= 1.5.10)
|
|
34
37
|
rake
|
|
35
38
|
rdoc
|
|
39
|
+
semver
|
|
36
40
|
json (1.8.3)
|
|
37
|
-
jwt (1.5.
|
|
38
|
-
|
|
39
|
-
|
|
41
|
+
jwt (1.5.6)
|
|
42
|
+
mini_portile2 (2.1.0)
|
|
43
|
+
minitest (5.9.1)
|
|
44
|
+
multi_json (1.12.1)
|
|
40
45
|
multi_xml (0.5.5)
|
|
41
|
-
multipart-post (
|
|
42
|
-
nokogiri (1.
|
|
43
|
-
|
|
46
|
+
multipart-post (2.0.0)
|
|
47
|
+
nokogiri (1.6.8.1)
|
|
48
|
+
mini_portile2 (~> 2.1.0)
|
|
49
|
+
oauth2 (1.2.0)
|
|
44
50
|
faraday (>= 0.8, < 0.10)
|
|
45
|
-
jwt (~> 1.0
|
|
51
|
+
jwt (~> 1.0)
|
|
46
52
|
multi_json (~> 1.3)
|
|
47
53
|
multi_xml (~> 0.5)
|
|
48
54
|
rack (>= 1.2, < 3)
|
|
49
|
-
rack (
|
|
50
|
-
rake (11.
|
|
51
|
-
rdoc (
|
|
55
|
+
rack (2.0.1)
|
|
56
|
+
rake (11.3.0)
|
|
57
|
+
rdoc (4.2.2)
|
|
52
58
|
json (~> 1.4)
|
|
53
|
-
rspec (
|
|
54
|
-
rspec-core (~>
|
|
55
|
-
rspec-expectations (~>
|
|
56
|
-
rspec-mocks (~>
|
|
57
|
-
rspec-core (
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
rspec (3.5.0)
|
|
60
|
+
rspec-core (~> 3.5.0)
|
|
61
|
+
rspec-expectations (~> 3.5.0)
|
|
62
|
+
rspec-mocks (~> 3.5.0)
|
|
63
|
+
rspec-core (3.5.4)
|
|
64
|
+
rspec-support (~> 3.5.0)
|
|
65
|
+
rspec-expectations (3.5.0)
|
|
66
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
67
|
+
rspec-support (~> 3.5.0)
|
|
68
|
+
rspec-mocks (3.5.0)
|
|
69
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
70
|
+
rspec-support (~> 3.5.0)
|
|
71
|
+
rspec-support (3.5.0)
|
|
72
|
+
semver (1.0.1)
|
|
61
73
|
thread_safe (0.3.5)
|
|
62
74
|
tzinfo (1.2.2)
|
|
63
75
|
thread_safe (~> 0.1)
|
|
@@ -67,11 +79,11 @@ PLATFORMS
|
|
|
67
79
|
|
|
68
80
|
DEPENDENCIES
|
|
69
81
|
activesupport
|
|
70
|
-
bundler
|
|
71
|
-
htmlentities
|
|
72
|
-
jeweler
|
|
73
|
-
rdoc
|
|
74
|
-
rspec
|
|
82
|
+
bundler
|
|
83
|
+
htmlentities
|
|
84
|
+
jeweler
|
|
85
|
+
rdoc
|
|
86
|
+
rspec
|
|
75
87
|
|
|
76
88
|
BUNDLED WITH
|
|
77
|
-
1.
|
|
89
|
+
1.12.5
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.
|
|
1
|
+
0.4.0
|
data/lib/smart_name.rb
CHANGED
|
@@ -10,12 +10,14 @@ class SmartName < Object
|
|
|
10
10
|
|
|
11
11
|
include ActiveSupport::Configurable
|
|
12
12
|
|
|
13
|
-
config_accessor :joint, :banned_array, :var_re, :uninflect, :params, :session
|
|
13
|
+
config_accessor :joint, :banned_array, :var_re, :uninflect, :params, :session, :stabilize
|
|
14
14
|
|
|
15
15
|
SmartName.joint = '+'
|
|
16
16
|
SmartName.banned_array = ['/', '~', '|']
|
|
17
17
|
SmartName.var_re = /\{([^\}]*\})\}/
|
|
18
18
|
SmartName.uninflect = :singularize
|
|
19
|
+
SmartName.stabilize = false
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
JOINT_RE = Regexp.escape joint
|
|
21
23
|
|
|
@@ -35,6 +37,20 @@ class SmartName < Object
|
|
|
35
37
|
def banned_re
|
|
36
38
|
%r{#{ (['['] + banned_array << joint) * '\\' + ']' }}
|
|
37
39
|
end
|
|
40
|
+
|
|
41
|
+
# Sometimes the core rule "the key's key must be itself" (called "stable" below) is violated
|
|
42
|
+
# eg. it fails with singularize as uninflect method for Matthias -> Matthia -> Matthium
|
|
43
|
+
# Usually that means the name is a proper noun and not a plural.
|
|
44
|
+
# You can choose between two solutions:
|
|
45
|
+
# 1. don't uninflect if the uninflected key is not stable (stabilize = false)
|
|
46
|
+
# (probably the best choice because you want Matthias not to be the same as Matthium)
|
|
47
|
+
# 2. uninflect until the key is stable (stabilize = true)
|
|
48
|
+
def stable_uninflect name
|
|
49
|
+
key_one = name.send(SmartName.uninflect)
|
|
50
|
+
key_two = key_one.send(SmartName.uninflect)
|
|
51
|
+
return key_one unless key_one != key_two
|
|
52
|
+
SmartName.stabilize ? stable_uninflect(key_two) : name
|
|
53
|
+
end
|
|
38
54
|
end
|
|
39
55
|
|
|
40
56
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
@@ -104,7 +120,8 @@ class SmartName < Object
|
|
|
104
120
|
.gsub(/[^#{OK4KEY_RE}]+/, '_')
|
|
105
121
|
.split(/_+/)
|
|
106
122
|
.reject(&:empty?)
|
|
107
|
-
.map(
|
|
123
|
+
.map { |key| SmartName.stable_uninflect(key) }
|
|
124
|
+
.join('_')
|
|
108
125
|
end
|
|
109
126
|
|
|
110
127
|
def url_key
|
data/spec/lib/smart_name_spec.rb
CHANGED
|
@@ -62,6 +62,26 @@ describe SmartName do
|
|
|
62
62
|
'Jean-françois Noubel'.to_name.key.should == 'jean_françoi_noubel'
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
|
+
|
|
66
|
+
describe 'unstable keys' do
|
|
67
|
+
context 'stabilize' do
|
|
68
|
+
before do
|
|
69
|
+
SmartName.stabilize = true
|
|
70
|
+
end
|
|
71
|
+
it 'should uninflect until key is stable' do
|
|
72
|
+
"matthias".to_name.key.should == "matthium"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context 'do not stabilize' do
|
|
77
|
+
before do
|
|
78
|
+
SmartName.stabilize = false
|
|
79
|
+
end
|
|
80
|
+
it 'should not uninflect unstable names' do
|
|
81
|
+
"ilias".to_name.key.should == "ilias"
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
65
85
|
|
|
66
86
|
describe 'parts and pieces' do
|
|
67
87
|
it 'should produce simple strings for parts' do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: smartname
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gerry Gleason
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2016-
|
|
12
|
+
date: 2016-11-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activesupport
|
|
@@ -29,72 +29,72 @@ dependencies:
|
|
|
29
29
|
name: htmlentities
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
|
32
|
-
- - "
|
|
32
|
+
- - ">="
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version:
|
|
34
|
+
version: '0'
|
|
35
35
|
type: :runtime
|
|
36
36
|
prerelease: false
|
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
38
|
requirements:
|
|
39
|
-
- - "
|
|
39
|
+
- - ">="
|
|
40
40
|
- !ruby/object:Gem::Version
|
|
41
|
-
version:
|
|
41
|
+
version: '0'
|
|
42
42
|
- !ruby/object:Gem::Dependency
|
|
43
43
|
name: rspec
|
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
|
-
- - "
|
|
46
|
+
- - ">="
|
|
47
47
|
- !ruby/object:Gem::Version
|
|
48
|
-
version:
|
|
48
|
+
version: '0'
|
|
49
49
|
type: :development
|
|
50
50
|
prerelease: false
|
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
|
-
- - "
|
|
53
|
+
- - ">="
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
|
-
version:
|
|
55
|
+
version: '0'
|
|
56
56
|
- !ruby/object:Gem::Dependency
|
|
57
57
|
name: rdoc
|
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
|
60
|
-
- - "
|
|
60
|
+
- - ">="
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: '
|
|
62
|
+
version: '0'
|
|
63
63
|
type: :development
|
|
64
64
|
prerelease: false
|
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
|
66
66
|
requirements:
|
|
67
|
-
- - "
|
|
67
|
+
- - ">="
|
|
68
68
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: '
|
|
69
|
+
version: '0'
|
|
70
70
|
- !ruby/object:Gem::Dependency
|
|
71
71
|
name: bundler
|
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
|
73
73
|
requirements:
|
|
74
|
-
- - "
|
|
74
|
+
- - ">="
|
|
75
75
|
- !ruby/object:Gem::Version
|
|
76
|
-
version: '
|
|
76
|
+
version: '0'
|
|
77
77
|
type: :development
|
|
78
78
|
prerelease: false
|
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
|
80
80
|
requirements:
|
|
81
|
-
- - "
|
|
81
|
+
- - ">="
|
|
82
82
|
- !ruby/object:Gem::Version
|
|
83
|
-
version: '
|
|
83
|
+
version: '0'
|
|
84
84
|
- !ruby/object:Gem::Dependency
|
|
85
85
|
name: jeweler
|
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
|
87
87
|
requirements:
|
|
88
|
-
- - "
|
|
88
|
+
- - ">="
|
|
89
89
|
- !ruby/object:Gem::Version
|
|
90
|
-
version:
|
|
90
|
+
version: '0'
|
|
91
91
|
type: :development
|
|
92
92
|
prerelease: false
|
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
|
94
94
|
requirements:
|
|
95
|
-
- - "
|
|
95
|
+
- - ">="
|
|
96
96
|
- !ruby/object:Gem::Version
|
|
97
|
-
version:
|
|
97
|
+
version: '0'
|
|
98
98
|
description: Naming patterns abstracted from the Wagn platform
|
|
99
99
|
email: gerryg@inbox.com
|
|
100
100
|
executables: []
|
|
@@ -136,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
136
136
|
version: '0'
|
|
137
137
|
requirements: []
|
|
138
138
|
rubyforge_project:
|
|
139
|
-
rubygems_version: 2.
|
|
139
|
+
rubygems_version: 2.6.6
|
|
140
140
|
signing_key:
|
|
141
141
|
specification_version: 4
|
|
142
142
|
summary: Wagn names without all the wagn
|
|
143
143
|
test_files: []
|
|
144
|
-
has_rdoc:
|