lite-ruby 1.0.30 → 1.0.31

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: 497a85ac4bea67a37f713e049589a1825e1ea9c2cb157ad5b9aba5b89ed0c37e
4
- data.tar.gz: 7f4747cdcff9975cec2d43cb929223bb26ca43939ab60a3dee46d378252fdabe
3
+ metadata.gz: 15a0127d8b5abef7b86a8b357d76bd81721b3e17633e25935d074c914f2ce6c9
4
+ data.tar.gz: 0e0cbbb3cb414574370770851e3423b1f09094d1aebd0a133897c24ad9b40588
5
5
  SHA512:
6
- metadata.gz: 4f63e2c228b2e4eb349a4b9c14187e906f3bb5803ea7188a352c4bbc6f82ac2867148b68acd92e8c5a758d9e57943f9410c72d380295953fa8e741b0734e3260
7
- data.tar.gz: c1416d519e4ec7d8a3c0fad863145789cc55a262d293bacc9df6927ecc92d04b3464eee778dede669a33ecafdca6e2c4f51b725ffdc76735ec16c7a730447eac
6
+ metadata.gz: 28cb3f81b2df9ff0483153c8c7077c04220efa0012958d6533cd8903a6d7b22e1099ab77c5c3db6b024cf04d211c37eb8bae9581e6457c02ddf1d891a5bf7142
7
+ data.tar.gz: 5adfc54f1824eab97ab7f23f20ea4b33f3405fddbd97ba32d48fa93f883eb35e0f6f9d70ac24f39ff046ae5a0775a080e0fcffaea1cfd4ce3e353e50afcd1bf8
@@ -6,6 +6,8 @@ AllCops:
6
6
  NewCops: enable
7
7
  DisplayCopNames: true
8
8
  DisplayStyleGuide: true
9
+ Gemspec/RequiredRubyVersion:
10
+ Enabled: false
9
11
  Layout/EmptyLinesAroundBlockBody:
10
12
  Exclude:
11
13
  - 'spec/**/**/*'
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.31] - 2020-09-21
10
+ ### Changed
11
+ - Changed `block_given?` => `defined?(yield)` for more performance
12
+
9
13
  ## [1.0.30] - 2020-07-03
10
14
  ### Added
11
15
  - Added more Ruby 2.7 support
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.30)
4
+ lite-ruby (1.0.31)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (6.0.3.2)
10
- actionview (= 6.0.3.2)
11
- activesupport (= 6.0.3.2)
9
+ actionpack (6.0.3.3)
10
+ actionview (= 6.0.3.3)
11
+ activesupport (= 6.0.3.3)
12
12
  rack (~> 2.0, >= 2.0.8)
13
13
  rack-test (>= 0.6.3)
14
14
  rails-dom-testing (~> 2.0)
15
15
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
16
- actionview (6.0.3.2)
17
- activesupport (= 6.0.3.2)
16
+ actionview (6.0.3.3)
17
+ activesupport (= 6.0.3.3)
18
18
  builder (~> 3.1)
19
19
  erubi (~> 1.4)
20
20
  rails-dom-testing (~> 2.0)
21
21
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
- activesupport (6.0.3.2)
22
+ activesupport (6.0.3.3)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
24
  i18n (>= 0.7, < 2)
25
25
  minitest (~> 5.1)
@@ -28,7 +28,7 @@ GEM
28
28
  ast (2.4.1)
29
29
  builder (3.2.4)
30
30
  colorize (0.8.1)
31
- concurrent-ruby (1.1.6)
31
+ concurrent-ruby (1.1.7)
32
32
  crass (1.0.6)
33
33
  diff-lcs (1.4.4)
34
34
  erubi (1.9.0)
@@ -38,15 +38,15 @@ GEM
38
38
  generator_spec (0.9.4)
39
39
  activesupport (>= 3.0.0)
40
40
  railties (>= 3.0.0)
41
- i18n (1.8.3)
41
+ i18n (1.8.5)
42
42
  concurrent-ruby (~> 1.0)
43
- loofah (2.6.0)
43
+ loofah (2.7.0)
44
44
  crass (~> 1.0.2)
45
45
  nokogiri (>= 1.5.9)
46
46
  method_source (1.0.0)
47
47
  mini_portile2 (2.4.0)
48
- minitest (5.14.1)
49
- nokogiri (1.10.9)
48
+ minitest (5.14.2)
49
+ nokogiri (1.10.10)
50
50
  mini_portile2 (~> 2.4.0)
51
51
  parallel (1.19.2)
52
52
  parser (2.7.1.4)
@@ -59,15 +59,15 @@ GEM
59
59
  nokogiri (>= 1.6)
60
60
  rails-html-sanitizer (1.3.0)
61
61
  loofah (~> 2.3)
62
- railties (6.0.3.2)
63
- actionpack (= 6.0.3.2)
64
- activesupport (= 6.0.3.2)
62
+ railties (6.0.3.3)
63
+ actionpack (= 6.0.3.3)
64
+ activesupport (= 6.0.3.3)
65
65
  method_source
66
66
  rake (>= 0.8.7)
67
67
  thor (>= 0.20.3, < 2.0)
68
68
  rainbow (3.0.0)
69
69
  rake (13.0.1)
70
- regexp_parser (1.7.1)
70
+ regexp_parser (1.8.0)
71
71
  rexml (3.2.4)
72
72
  rspec (3.9.0)
73
73
  rspec-core (~> 3.9.0)
@@ -82,31 +82,32 @@ GEM
82
82
  diff-lcs (>= 1.2.0, < 2.0)
83
83
  rspec-support (~> 3.9.0)
84
84
  rspec-support (3.9.3)
85
- rubocop (0.86.0)
85
+ rubocop (0.91.0)
86
86
  parallel (~> 1.10)
87
- parser (>= 2.7.0.1)
87
+ parser (>= 2.7.1.1)
88
88
  rainbow (>= 2.2.2, < 4.0)
89
89
  regexp_parser (>= 1.7)
90
90
  rexml
91
- rubocop-ast (>= 0.0.3, < 1.0)
91
+ rubocop-ast (>= 0.4.0, < 1.0)
92
92
  ruby-progressbar (~> 1.7)
93
93
  unicode-display_width (>= 1.4.0, < 2.0)
94
- rubocop-ast (0.1.0)
95
- parser (>= 2.7.0.1)
96
- rubocop-performance (1.6.1)
97
- rubocop (>= 0.71.0)
98
- rubocop-rspec (1.41.0)
99
- rubocop (>= 0.68.1)
94
+ rubocop-ast (0.4.2)
95
+ parser (>= 2.7.1.4)
96
+ rubocop-performance (1.8.1)
97
+ rubocop (>= 0.87.0)
98
+ rubocop-ast (>= 0.4.0)
99
+ rubocop-rspec (1.43.2)
100
+ rubocop (~> 0.87)
100
101
  ruby-progressbar (1.10.1)
101
- ruby_parser (3.14.2)
102
+ ruby_parser (3.15.0)
102
103
  sexp_processor (~> 4.9)
103
- sexp_processor (4.15.0)
104
+ sexp_processor (4.15.1)
104
105
  thor (1.0.1)
105
106
  thread_safe (0.3.6)
106
107
  tzinfo (1.2.7)
107
108
  thread_safe (~> 0.1)
108
109
  unicode-display_width (1.7.0)
109
- zeitwerk (2.3.1)
110
+ zeitwerk (2.4.0)
110
111
 
111
112
  PLATFORMS
112
113
  ruby
@@ -323,8 +323,8 @@ Moves a key value pair to the head of the hash.
323
323
  Rename the keys of a hash.
324
324
 
325
325
  ```ruby
326
- { foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar) #=> { bar: 'foo', baz: 'baz' }
327
- { foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick') #=> { bar: 'foo', tick: 'baz' }
326
+ { foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar) #=> { bar: 'foo', baz: 'baz' }
327
+ { foo: 'foo', 'baz' => 'baz' }.rename_keys!(foo: :bar, 'baz' => 'tick') #=> { bar: 'foo', tick: 'baz' }
328
328
  ```
329
329
 
330
330
  `reverse_merge(!)`
@@ -4,11 +4,14 @@
4
4
  require "lite/ruby/#{filename}"
5
5
  end
6
6
 
7
+ %w[date time].each do |filename|
8
+ require "lite/ruby/helpers/#{filename}_helper"
9
+ end
10
+
7
11
  %w[
8
12
  array boolean date enumerable hash integer kernel numeric object open_struct range string
9
13
  struct time
10
14
  ].each do |filename|
11
- require "lite/ruby/helpers/#{filename}_helper" if %w[date time].include?(filename)
12
15
  require "lite/ruby/#{filename}"
13
16
  end
14
17
 
@@ -184,7 +184,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
184
184
  end
185
185
 
186
186
  # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
187
- def in_groups(number, fill_with = nil)
187
+ def in_groups(number, fill_with = nil, &block)
188
188
  collection_size = size
189
189
  division = collection_size.div(number)
190
190
  modulo = collection_size % number
@@ -199,14 +199,14 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
199
199
  start += grouping
200
200
  end
201
201
 
202
- return collection unless block_given?
202
+ return collection unless defined?(yield)
203
203
 
204
- collection.each { |val| yield(val) }
204
+ collection.each(&block)
205
205
  end
206
206
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
207
207
 
208
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Style/GuardClause
209
- def in_groups_of(number, fill_with = nil)
208
+ # rubocop:disable Metrics/MethodLength, Style/GuardClause
209
+ def in_groups_of(number, fill_with = nil, &block)
210
210
  if number.to_i <= 0
211
211
  raise ArgumentError, "Group size must be a positive integer, was #{number.inspect}"
212
212
  elsif fill_with == false
@@ -217,11 +217,11 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
217
217
  end
218
218
 
219
219
  sliced_collection = collection.each_slice(number)
220
- return sliced_collection.to_a unless block_given?
220
+ return sliced_collection.to_a unless defined?(yield)
221
221
 
222
- sliced_collection { |val| yield(val) }
222
+ sliced_collection(&block)
223
223
  end
224
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Style/GuardClause
224
+ # rubocop:enable Metrics/MethodLength, Style/GuardClause
225
225
 
226
226
  def indexes(value)
227
227
  array = []
@@ -311,7 +311,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
311
311
  def split(number = nil)
312
312
  array = [[]]
313
313
 
314
- if block_given?
314
+ if defined?(yield)
315
315
  each { |val| yield(val) ? (array << []) : (array.last << val) }
316
316
  else
317
317
  dup_arr = dup
@@ -20,7 +20,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
20
20
  end
21
21
 
22
22
  def deduce(identity = 0, &block)
23
- if block_given?
23
+ if defined?(yield)
24
24
  map(&block).deduce(identity)
25
25
  else
26
26
  inject { |acc, val| acc - val } || identity
@@ -46,7 +46,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
46
46
  def exactly?(num)
47
47
  found_count = 0
48
48
 
49
- if block_given?
49
+ if defined?(yield)
50
50
  each { |*opt| found_count += 1 if yield(*opt) }
51
51
  else
52
52
  each { |opt| found_count += 1 if opt }
@@ -77,7 +77,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
77
77
  end
78
78
 
79
79
  def exponential(identity = 0, &block)
80
- if block_given?
80
+ if defined?(yield)
81
81
  map(&block).exponential(identity)
82
82
  else
83
83
  inject { |acc, val| acc**val } || identity
@@ -131,7 +131,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
131
131
  def many?
132
132
  found_count = 0
133
133
 
134
- if block_given?
134
+ if defined?(yield)
135
135
  any? do |val|
136
136
  found_count += 1 if yield(val)
137
137
  found_count > 1
@@ -153,7 +153,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
153
153
  end
154
154
  end
155
155
 
156
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
156
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity
157
+ # rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity
157
158
  def occur(amount = nil)
158
159
  result = Hash.new { |hash, key| hash[key] = [] }
159
160
 
@@ -162,7 +163,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
162
163
  result[key] << item
163
164
  end
164
165
 
165
- if block_given?
166
+ if defined?(yield)
166
167
  result.select! { |_key, values| yield(values.size) }
167
168
  else
168
169
  raise ArgumentError, 'Invalid occur amount' unless amount
@@ -176,7 +177,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
176
177
 
177
178
  result.values.flatten.uniq
178
179
  end
179
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
180
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
181
+ # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
180
182
 
181
183
  def pluck(*keys)
182
184
  if keys.many?
@@ -187,7 +189,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
187
189
  end
188
190
 
189
191
  def produce(identity = 0, &block)
190
- if block_given?
192
+ if defined?(yield)
191
193
  map(&block).produce(identity)
192
194
  else
193
195
  inject { |acc, val| acc * val } || identity
@@ -195,7 +197,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
195
197
  end
196
198
 
197
199
  def quotient(identity = 0, &block)
198
- if block_given?
200
+ if defined?(yield)
199
201
  map(&block).quotient(identity)
200
202
  else
201
203
  inject { |acc, val| acc / val } || identity
@@ -205,7 +207,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
205
207
  def several?
206
208
  found_count = 0
207
209
 
208
- if block_given?
210
+ if defined?(yield)
209
211
  each { |*opt| found_count += 1 if yield(*opt) }
210
212
  else
211
213
  each { |opt| found_count += 1 if opt }
@@ -102,7 +102,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
102
102
  end
103
103
  # rubocop:enable Style/GuardClause
104
104
 
105
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
105
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
106
106
  def collate(*others)
107
107
  hash = {}
108
108
 
@@ -121,18 +121,18 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
121
121
  hash.each_value(&:flatten!)
122
122
  hash
123
123
  end
124
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
124
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
125
125
 
126
126
  def collate!(other_hash)
127
127
  replace(collate(other_hash))
128
128
  end
129
129
 
130
- def collect_keys
131
- collect { |key, _| yield(key) }
130
+ def collect_keys(&block)
131
+ keys.map(&block)
132
132
  end
133
133
 
134
- def collect_values
135
- collect { |_, val| yield(val) }
134
+ def collect_values(&block)
135
+ values.map(&block)
136
136
  end
137
137
 
138
138
  def dearray_values(idx = 0)
@@ -186,7 +186,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
186
186
  merge!(other_hash) do |key, this_val, other_val|
187
187
  if this_val.is_a?(Hash) && other_val.is_a?(Hash)
188
188
  this_val.deep_merge(other_val, &block)
189
- elsif block_given?
189
+ elsif defined?(yield)
190
190
  yield(key, this_val, other_val)
191
191
  else
192
192
  other_val
@@ -403,10 +403,10 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
403
403
  def symbolize_keys
404
404
  each_with_object({}) do |(key, val), hash|
405
405
  new_key = begin
406
- key.to_s.to_sym
407
- rescue StandardError
408
- key
409
- end
406
+ key.to_s.to_sym
407
+ rescue StandardError
408
+ key
409
+ end
410
410
 
411
411
  hash[new_key] = val
412
412
  end
@@ -420,16 +420,16 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
420
420
  def symbolize_and_underscore_keys
421
421
  each_with_object({}) do |(key, val), hash|
422
422
  new_key = begin
423
- key.to_s
424
- .gsub(/::/, '/')
425
- .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
426
- .gsub(/([a-z\d])([A-Z])/, '\1_\2')
427
- .tr(' -', '_')
428
- .downcase
429
- .to_sym
430
- rescue StandardError
431
- key
432
- end
423
+ key.to_s
424
+ .gsub(/::/, '/')
425
+ .gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
426
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
427
+ .tr(' -', '_')
428
+ .downcase
429
+ .to_sym
430
+ rescue StandardError
431
+ key
432
+ end
433
433
 
434
434
  hash[new_key] = val
435
435
  end
@@ -462,13 +462,13 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
462
462
  end
463
463
 
464
464
  def update_keys
465
- return to_enum(:update_keys) unless block_given?
465
+ return to_enum(:update_keys) unless defined?(yield)
466
466
 
467
467
  replace(each_with_object({}) { |(key, val), hash| hash[yield(key)] = val })
468
468
  end
469
469
 
470
470
  def update_values
471
- return to_enum(:update_values) unless block_given?
471
+ return to_enum(:update_values) unless defined?(yield)
472
472
 
473
473
  replace(each_with_object({}) { |(key, val), hash| hash[key] = yield(val) })
474
474
  end
@@ -86,7 +86,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
86
86
  end
87
87
 
88
88
  def fraction?
89
- fraction != 0.0
89
+ fraction.to_d != 0.0.to_d
90
90
  end
91
91
 
92
92
  def greater_than?(num)
@@ -173,7 +173,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
173
173
  to_s.rjust(precision, pad_number.to_s)
174
174
  end
175
175
 
176
- # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
176
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
177
177
  def pad_precision(options = {})
178
178
  pad_number = options[:pad_number] || 0
179
179
  precision = options[:precision] || 2
@@ -190,7 +190,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
190
190
  string[0..(ljust_count - 1)]
191
191
  end
192
192
  end
193
- # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
193
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
194
194
 
195
195
  def percentage_of(number)
196
196
  return 0 if zero? || number.zero?
@@ -177,7 +177,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
177
177
  end
178
178
 
179
179
  def try!(*obj, &block)
180
- if obj.empty? && block_given?
180
+ if obj.empty? && defined?(yield)
181
181
  block.arity.zero? ? instance_eval(&block) : yield(self)
182
182
  else
183
183
  public_send(*obj, &block)
@@ -369,7 +369,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
369
369
  b = f
370
370
 
371
371
  if amount.odd?
372
- f = "'" + f
372
+ f = "'#{f}"
373
373
  b += "'"
374
374
  end
375
375
  else
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.30'
6
+ VERSION ||= '1.0.31'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.30
4
+ version: 1.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-03 00:00:00.000000000 Z
11
+ date: 2020-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler