gorilla_patch 2.9.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f92aeb3963b9338d0e209fbc2711e72cbd1539f6673fee3b225b1c88c1b84cca
4
- data.tar.gz: 1b6e53f0a1534575a7b19ff5e29c057f8f7aebfb0c8b64f562acace5bfc980a9
3
+ metadata.gz: aabed6279d43a45280eb596358b59ca87a5caac5471f277897d3b2e03de43b30
4
+ data.tar.gz: 6a8e023016eeb23f67edf6d784422ce3682fd17caed9abaf929060b3f4d42b38
5
5
  SHA512:
6
- metadata.gz: f924dd8b2762aea63511302906290fda9a597296a918ee30ae01341e68369a11d9766056944b0ba9bd87f98d3fbc755c7ccf1d8b729644a5a432d18ecd8154bb
7
- data.tar.gz: c7aa80a28a8406bd9b845200a0f367106579ee88778df7896d76ecd3fc7984aa6c995c9be0f836cbf985e46e3d823fbc8d30553af555d89de1852393ea893a7b
6
+ metadata.gz: 4c6e7cfefd3add89b69408e7570822c138c077a8c30e9ddec4769e8d42f59dae02291cc7e362b69935c3f7ff841280ecaad882921419ec8b9bcee1270f19ae58
7
+ data.tar.gz: b2b1ca556a29e02a65fb2d4e019b3ed18bca8aed7e1befe04ada9b69822ef7acf474b8a60da3e5effec1e6dfc51c0690028e08b91394efd79261eba71ff1b36f
@@ -2,4 +2,4 @@
2
2
 
3
3
  Dir.glob(
4
4
  File.join(__dir__, 'gorilla_patch', '*.rb')
5
- ).each { |file| require file }
5
+ ).sort.each { |file| require file }
@@ -17,6 +17,12 @@ module GorillaPatch
17
17
  end
18
18
  end
19
19
 
20
+ refine Object do
21
+ def blank?
22
+ respond_to?(:empty?) ? empty? : !self
23
+ end
24
+ end
25
+
20
26
  # rubocop:disable Metrics/BlockLength
21
27
  REFINED_ENUMERABLES = [Array, Hash].freeze
22
28
 
@@ -5,7 +5,8 @@ module GorillaPatch
5
5
  module Cover
6
6
  refine Range do
7
7
  def cover?(value)
8
- return super unless value.is_a? Range
8
+ return super unless value.is_a?(Range) && RUBY_VERSION < '2.6'
9
+
9
10
  super(value.first) && super(value.last)
10
11
  end
11
12
  end
@@ -6,11 +6,6 @@ module GorillaPatch
6
6
  refine Object do
7
7
  def deep_dup
8
8
  dup
9
- rescue TypeError
10
- # :nocov:
11
- # For Ruby < 2.4: https://bugs.ruby-lang.org/issues/12979
12
- self
13
- # :nocov:
14
9
  end
15
10
  end
16
11
 
@@ -24,7 +19,7 @@ module GorillaPatch
24
19
 
25
20
  refine Array do
26
21
  def deep_dup
27
- map { |el| el.deep_dup }
22
+ map(&:deep_dup)
28
23
  end
29
24
  end
30
25
 
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'deep_dup'
4
+
3
5
  module GorillaPatch
4
6
  ## Adding deep_merge method
5
7
  module DeepMerge
@@ -14,8 +16,10 @@ module GorillaPatch
14
16
  self
15
17
  end
16
18
 
19
+ using GorillaPatch::DeepDup
20
+
17
21
  def deep_merge(other_hash, &block)
18
- dup.deep_merge!(other_hash, &block)
22
+ deep_dup.deep_merge!(other_hash, &block)
19
23
  end
20
24
 
21
25
  private
@@ -3,29 +3,44 @@
3
3
  module GorillaPatch
4
4
  ## Inflections
5
5
  module Inflections
6
- def self.acronyms
7
- @acronyms ||= %w[API HTML XML JSON SSL IP HTTP HTTPS]
6
+ class << self
7
+ ## Set of acronyms which can be modified externally
8
+ def acronyms
9
+ @acronyms ||= %w[
10
+ API DateTime FAQ HTML HTTP HTTPS ID IP JSON SEO SSL UTM XML
11
+ ]
12
+ end
13
+
14
+ ## Regular expression for detecting known acronyms
15
+ def acronyms_regex
16
+ /(?:(?<=([A-Z\d_]))|\b)((?i)#{acronyms.join('|')})(?=\b|[^a-z])/
17
+ end
8
18
  end
9
19
 
10
20
  refine String do
11
21
  def underscore
12
- gsub(/::/, '/')
13
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
14
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
15
- .tr('-', '_')
16
- .downcase
22
+ result = gsub('::', '/')
23
+ result.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
24
+ result.gsub!(GorillaPatch::Inflections.acronyms_regex) do
25
+ "#{Regexp.last_match(1) && '_'}#{Regexp.last_match(2).downcase}"
26
+ end
27
+ result.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
28
+ result.tr!('-', '_')
29
+ result.downcase
17
30
  end
18
31
 
19
32
  def camelize
20
33
  acronyms = GorillaPatch::Inflections.acronyms
21
- split('/')
22
- .map do |s|
23
- s.split(/([[:upper:]][[:lower:]]*)|_|-/).collect do |part|
24
- upcased_part = part.upcase
25
- acronyms.include?(upcased_part) ? upcased_part : part.capitalize
26
- end.join
34
+
35
+ result = gsub(GorillaPatch::Inflections.acronyms_regex) do
36
+ acronyms.find do |acronym|
37
+ acronym.downcase == Regexp.last_match(2).downcase
27
38
  end
28
- .join('::')
39
+ end
40
+ result.gsub!(%r{(?:^|_|-|(/))([a-z\d]*)}) do
41
+ "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}"
42
+ end
43
+ result.gsub('/', '::')
29
44
  end
30
45
  end
31
46
 
@@ -35,24 +50,65 @@ module GorillaPatch
35
50
  end
36
51
  end
37
52
 
53
+ ## Use inflections from Sequel
38
54
  def self.from_sequel
39
55
  @from_sequel ||= Module.new do
40
56
  require 'sequel'
41
57
 
42
58
  refine String do
43
- Sequel::Inflections.private_instance_methods.each do |method|
44
- define_method method do
45
- Sequel::Inflections.instance_method(method).bind(self).call(self)
46
- end
59
+ extend MethodsFromSequel
60
+
61
+ define_methods_from_sequel
62
+ end
63
+ end
64
+ end
65
+
66
+ ## Module for definition methods from Sequel
67
+ ## https://sequel.jeremyevans.net/
68
+ module MethodsFromSequel
69
+ private
70
+
71
+ def define_methods_from_sequel
72
+ Sequel::Inflections.private_instance_methods.each do |method_name|
73
+ define_method method_name do
74
+ Sequel::Inflections.instance_method(method_name)
75
+ .bind(self).call(self)
47
76
  end
48
77
  end
49
78
  end
50
79
  end
51
80
 
52
- def self.from_inflecto
53
- require 'inflecto-refinements'
81
+ private_constant :MethodsFromSequel
54
82
 
55
- Inflecto::Refinements
83
+ ## Use inflections from DRY Inflector
84
+ ## https://dry-rb.org/gems/dry-inflector/
85
+ def self.from_dry_inflector
86
+ @from_dry_inflector ||= Module.new do
87
+ require 'dry/inflector'
88
+
89
+ refine String do
90
+ extend MethodsFromDryInflector
91
+
92
+ define_methods_from_dry_inflector
93
+ end
94
+ end
56
95
  end
96
+
97
+ ## Module for definition methods from Dry::Inflector
98
+ module MethodsFromDryInflector
99
+ private
100
+
101
+ def define_methods_from_dry_inflector
102
+ inflector = Dry::Inflector.new
103
+
104
+ inflector.public_methods.each do |method_name|
105
+ define_method method_name do
106
+ inflector.public_send method_name, self
107
+ end
108
+ end
109
+ end
110
+ end
111
+
112
+ private_constant :MethodsFromDryInflector
57
113
  end
58
114
  end
@@ -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
@@ -6,6 +6,7 @@ module GorillaPatch
6
6
  refine Hash do
7
7
  def slice(*keys, nils: false)
8
8
  return super if defined?(super) && !nils
9
+
9
10
  keys.each_with_object(self.class.new) do |k, hash|
10
11
  hash[k] = self[k] if nils || key?(k)
11
12
  end
@@ -6,6 +6,7 @@ module GorillaPatch
6
6
  refine String do
7
7
  def truncate(position, separator: '', omission: '...')
8
8
  return dup if length <= position
9
+
9
10
  stop = position - omission.length
10
11
  if separator.is_a?(Regexp) || !separator.empty?
11
12
  stop = rindex(separator, stop)
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GorillaPatch
4
+ VERSION = '4.0.0'
5
+ 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: 2.9.1
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-14 00:00:00.000000000 Z
11
+ date: 2020-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -16,98 +16,140 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.1.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry-byebug
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '12'
47
+ version: '13.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '12'
54
+ version: '13.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '3'
61
+ version: '3.0'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '3'
68
+ version: '3.0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '0.52'
75
+ version: 0.83.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.83.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-performance
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
62
104
  type: :development
63
105
  prerelease: false
64
106
  version_requirements: !ruby/object:Gem::Requirement
65
107
  requirements:
66
108
  - - "~>"
67
109
  - !ruby/object:Gem::Version
68
- version: '0.52'
110
+ version: '1.0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: simplecov
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - "~>"
74
116
  - !ruby/object:Gem::Version
75
- version: '0'
117
+ version: 0.18.0
76
118
  type: :development
77
119
  prerelease: false
78
120
  version_requirements: !ruby/object:Gem::Requirement
79
121
  requirements:
80
122
  - - "~>"
81
123
  - !ruby/object:Gem::Version
82
- version: '0'
124
+ version: 0.18.0
83
125
  - !ruby/object:Gem::Dependency
84
- name: inflecto-refinements
126
+ name: dry-inflector
85
127
  requirement: !ruby/object:Gem::Requirement
86
128
  requirements:
87
129
  - - "~>"
88
130
  - !ruby/object:Gem::Version
89
- version: '0'
131
+ version: 0.2.0
90
132
  type: :development
91
133
  prerelease: false
92
134
  version_requirements: !ruby/object:Gem::Requirement
93
135
  requirements:
94
136
  - - "~>"
95
137
  - !ruby/object:Gem::Version
96
- version: '0'
138
+ version: 0.2.0
97
139
  - !ruby/object:Gem::Dependency
98
140
  name: sequel
99
141
  requirement: !ruby/object:Gem::Requirement
100
142
  requirements:
101
143
  - - "~>"
102
144
  - !ruby/object:Gem::Version
103
- version: '5'
145
+ version: '5.0'
104
146
  type: :development
105
147
  prerelease: false
106
148
  version_requirements: !ruby/object:Gem::Requirement
107
149
  requirements:
108
150
  - - "~>"
109
151
  - !ruby/object:Gem::Version
110
- version: '5'
152
+ version: '5.0'
111
153
  description: Refine Ruby Core classes with methods like Active Support.
112
154
  email: alex.wayfer@gmail.com
113
155
  executables: []
@@ -124,16 +166,17 @@ files:
124
166
  - lib/gorilla_patch/except.rb
125
167
  - lib/gorilla_patch/inflections.rb
126
168
  - lib/gorilla_patch/keys.rb
169
+ - lib/gorilla_patch/module_parent.rb
127
170
  - lib/gorilla_patch/namespace.rb
128
171
  - lib/gorilla_patch/slice.rb
129
172
  - lib/gorilla_patch/symbolize.rb
130
- - lib/gorilla_patch/transform.rb
131
173
  - lib/gorilla_patch/truncate.rb
174
+ - lib/gorilla_patch/version.rb
132
175
  homepage: https://github.com/AlexWayfer/gorilla_patch
133
176
  licenses:
134
177
  - MIT
135
178
  metadata: {}
136
- post_install_message:
179
+ post_install_message:
137
180
  rdoc_options: []
138
181
  require_paths:
139
182
  - lib
@@ -141,16 +184,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
184
  requirements:
142
185
  - - ">="
143
186
  - !ruby/object:Gem::Version
144
- version: 2.1.0
187
+ version: 2.4.0
145
188
  required_rubygems_version: !ruby/object:Gem::Requirement
146
189
  requirements:
147
190
  - - ">="
148
191
  - !ruby/object:Gem::Version
149
192
  version: '0'
150
193
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.7.6
153
- signing_key:
194
+ rubygems_version: 3.1.2
195
+ signing_key:
154
196
  specification_version: 4
155
197
  summary: Refining core classes
156
198
  test_files: []
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GorillaPatch
4
- ## Module for transformations methods
5
- module Transform
6
- refine Hash do
7
- def transform_values
8
- return super if defined? super
9
- each_with_object(self.class.new) do |(key, value), result|
10
- result[key] = yield value
11
- end
12
- end
13
-
14
- def transform_values!
15
- return super if defined? super
16
- each do |key, value|
17
- self[key] = yield value
18
- end
19
- end
20
- end
21
- end
22
- end