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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2095e613a650d56e432d05bacc20c6a5204cebbd478115cea18721ec47685af3
4
- data.tar.gz: 18a2e07706a7dfd68990a18f009c5ed662371d707932d54b1bfe5fcf95954e7f
3
+ metadata.gz: 8fffde1193e008669e40de0d2532222a7a3a59e3bf01c3a8336c42e6bef4b939
4
+ data.tar.gz: b49e5e5b0a3afd9c7d390d1eba7900a2119a99748e44179c2d60730ddbba083a
5
5
  SHA512:
6
- metadata.gz: 0a1ff4b75bbdbf9964bb7bce72a2995035b647f0b41c17f4611b7fd607bcece9cdd8ff24113e884eb153201b8de67814f879764ccde58f9dc31f443c88090a1c
7
- data.tar.gz: 26fb993fa89868c4f44da75735f9b9767b09bedf00dc3cf43e04dcbfa3ea03bdab3e59d2386aed4625cb27ee1dfeb23157b1a56b79fca0513536a1b9ec8a0716
6
+ metadata.gz: 69699e4544a04c10286ad06b550fcc0914de4cac1b77b22ee5436a93b81f3000202cd6225d8f1d6abe2b044f101c79e08a6b3329d0764e39cdffa9284b165550
7
+ data.tar.gz: f2ffa7763652244a6bea7060b6da8ee9961b9f5501ccdb5e062770285113955435e9928c70a9a90394dd1f30301c87348465c37158b53b5b4401c34f3c577895
@@ -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
@@ -3,29 +3,40 @@
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
+ 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
- .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
14
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
15
- .tr('-', '_')
16
- .downcase
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
- 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
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
- .join('::')
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
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'blank'
4
+
5
+ module GorillaPatch
6
+ ## Adding blank methods
7
+ module Present
8
+ refine Object do
9
+ using GorillaPatch::Blank
10
+
11
+ def present?
12
+ !blank?
13
+ end
14
+ end
15
+ end
16
+ 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 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
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GorillaPatch
4
- VERSION = '3.0.1'
4
+ VERSION = '3.2.0'
5
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: 3.0.1
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: 2018-07-10 00:00:00.000000000 Z
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: '12'
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: '12'
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: '0.52'
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: '0.52'
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
- rubyforge_project:
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