gorilla_patch 3.0.1 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gorilla_patch/blank.rb +6 -0
- data/lib/gorilla_patch/cover.rb +2 -1
- data/lib/gorilla_patch/inflections.rb +25 -14
- data/lib/gorilla_patch/module_parent.rb +22 -0
- data/lib/gorilla_patch/present.rb +16 -0
- data/lib/gorilla_patch/slice.rb +1 -0
- data/lib/gorilla_patch/transform.rb +2 -0
- data/lib/gorilla_patch/truncate.rb +1 -0
- data/lib/gorilla_patch/version.rb +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fffde1193e008669e40de0d2532222a7a3a59e3bf01c3a8336c42e6bef4b939
|
4
|
+
data.tar.gz: b49e5e5b0a3afd9c7d390d1eba7900a2119a99748e44179c2d60730ddbba083a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69699e4544a04c10286ad06b550fcc0914de4cac1b77b22ee5436a93b81f3000202cd6225d8f1d6abe2b044f101c79e08a6b3329d0764e39cdffa9284b165550
|
7
|
+
data.tar.gz: f2ffa7763652244a6bea7060b6da8ee9961b9f5501ccdb5e062770285113955435e9928c70a9a90394dd1f30301c87348465c37158b53b5b4401c34f3c577895
|
data/lib/gorilla_patch/blank.rb
CHANGED
data/lib/gorilla_patch/cover.rb
CHANGED
@@ -3,29 +3,40 @@
|
|
3
3
|
module GorillaPatch
|
4
4
|
## Inflections
|
5
5
|
module Inflections
|
6
|
-
|
7
|
-
|
6
|
+
class << self
|
7
|
+
def acronyms
|
8
|
+
@acronyms ||= %w[API HTML XML JSON SSL ID IP HTTP HTTPS DateTime]
|
9
|
+
end
|
10
|
+
|
11
|
+
def acronyms_regex
|
12
|
+
/(?:(?<=([A-Z\d_]))|\b)((?i)#{acronyms.join('|')})(?=\b|[^a-z])/
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
refine String do
|
11
17
|
def underscore
|
12
|
-
gsub(
|
13
|
-
|
14
|
-
|
15
|
-
.
|
16
|
-
|
18
|
+
result = gsub('::', '/')
|
19
|
+
result.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
|
20
|
+
result.gsub!(GorillaPatch::Inflections.acronyms_regex) do
|
21
|
+
"#{Regexp.last_match(1) && '_'}#{Regexp.last_match(2).downcase}"
|
22
|
+
end
|
23
|
+
result.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
|
24
|
+
result.tr!('-', '_')
|
25
|
+
result.downcase
|
17
26
|
end
|
18
27
|
|
19
28
|
def camelize
|
20
29
|
acronyms = GorillaPatch::Inflections.acronyms
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
acronyms.include?(upcased_part) ? upcased_part : part.capitalize
|
26
|
-
end.join
|
30
|
+
|
31
|
+
result = gsub(GorillaPatch::Inflections.acronyms_regex) do
|
32
|
+
acronyms.find do |acronym|
|
33
|
+
acronym.downcase == Regexp.last_match(2).downcase
|
27
34
|
end
|
28
|
-
|
35
|
+
end
|
36
|
+
result.gsub!(%r{(?:^|_|-|(/))([a-z\d]*)}) do
|
37
|
+
"#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}"
|
38
|
+
end
|
39
|
+
result.gsub('/', '::')
|
29
40
|
end
|
30
41
|
end
|
31
42
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GorillaPatch
|
4
|
+
## Adding parent methods
|
5
|
+
module ModuleParent
|
6
|
+
refine Module do
|
7
|
+
def module_parent_name
|
8
|
+
if defined?(@module_parent_name)
|
9
|
+
@module_parent_name
|
10
|
+
else
|
11
|
+
module_parent_name = name =~ /::[^:]+\Z/ ? $`.freeze : nil
|
12
|
+
@module_parent_name = module_parent_name unless frozen?
|
13
|
+
module_parent_name
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def module_parent
|
18
|
+
module_parent_name ? Object.const_get(module_parent_name) : Object
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/gorilla_patch/slice.rb
CHANGED
@@ -6,6 +6,7 @@ module GorillaPatch
|
|
6
6
|
refine Hash do
|
7
7
|
def transform_values
|
8
8
|
return super if defined? super
|
9
|
+
|
9
10
|
each_with_object(self.class.new) do |(key, value), result|
|
10
11
|
result[key] = yield value
|
11
12
|
end
|
@@ -13,6 +14,7 @@ module GorillaPatch
|
|
13
14
|
|
14
15
|
def transform_values!
|
15
16
|
return super if defined? super
|
17
|
+
|
16
18
|
each do |key, value|
|
17
19
|
self[key] = yield value
|
18
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gorilla_patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Popov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.75.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.75.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,7 +124,9 @@ files:
|
|
124
124
|
- lib/gorilla_patch/except.rb
|
125
125
|
- lib/gorilla_patch/inflections.rb
|
126
126
|
- lib/gorilla_patch/keys.rb
|
127
|
+
- lib/gorilla_patch/module_parent.rb
|
127
128
|
- lib/gorilla_patch/namespace.rb
|
129
|
+
- lib/gorilla_patch/present.rb
|
128
130
|
- lib/gorilla_patch/slice.rb
|
129
131
|
- lib/gorilla_patch/symbolize.rb
|
130
132
|
- lib/gorilla_patch/transform.rb
|
@@ -149,8 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
151
|
- !ruby/object:Gem::Version
|
150
152
|
version: '0'
|
151
153
|
requirements: []
|
152
|
-
|
153
|
-
rubygems_version: 2.7.6
|
154
|
+
rubygems_version: 3.0.3
|
154
155
|
signing_key:
|
155
156
|
specification_version: 4
|
156
157
|
summary: Refining core classes
|