lite-ruby 1.0.31 → 1.1.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.
@@ -7,12 +7,12 @@ if Lite::Ruby.configuration.monkey_patches.include?('boolean')
7
7
  self
8
8
  end
9
9
 
10
- alias to_b to_bool
11
-
12
10
  def to_i
13
11
  0
14
12
  end
15
13
 
14
+ alias to_b to_bool
15
+
16
16
  end
17
17
 
18
18
  class TrueClass
@@ -21,11 +21,11 @@ if Lite::Ruby.configuration.monkey_patches.include?('boolean')
21
21
  self
22
22
  end
23
23
 
24
- alias to_b to_bool
25
-
26
24
  def to_i
27
25
  1
28
26
  end
29
27
 
28
+ alias to_b to_bool
29
+
30
30
  end
31
31
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
4
+ require 'lite/ruby/safe/enumerable' unless defined?(ActiveSupport)
5
+
4
6
  module Enumerable
5
7
 
6
8
  def cluster
@@ -61,17 +63,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
61
63
  end
62
64
  # rubocop:enable Style/CaseEquality
63
65
 
64
- def exclude?(object)
65
- !include?(object)
66
- end
67
-
68
- def excluding(*elements)
69
- elements.flatten!(1)
70
- reject { |element| elements.include?(element) }
71
- end
72
-
73
- alias without excluding
74
-
75
66
  def expand
76
67
  map { |val| val.is_a?(Enumerable) ? val.expand : val }
77
68
  end
@@ -88,20 +79,12 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
88
79
  each_with_object(Hash.new(0)) { |val, hash| hash[val] += 1 }
89
80
  end
90
81
 
91
- alias occurrences frequency
92
-
93
82
  # rubocop:disable Style/CaseEquality
94
83
  def incase?(object)
95
84
  any? { |val| object === val }
96
85
  end
97
86
  # rubocop:enable Style/CaseEquality
98
87
 
99
- def including(*elements)
100
- to_a.including(*elements)
101
- end
102
-
103
- alias with including
104
-
105
88
  # rubocop:disable Metrics/MethodLength
106
89
  def interpose(sep, &block)
107
90
  enum = Enumerator.new do |val|
@@ -128,19 +111,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
128
111
  end
129
112
  # rubocop:enable Metrics/MethodLength
130
113
 
131
- def many?
132
- found_count = 0
133
-
134
- if defined?(yield)
135
- any? do |val|
136
- found_count += 1 if yield(val)
137
- found_count > 1
138
- end
139
- else
140
- any? { (found_count += 1) > 1 }
141
- end
142
- end
143
-
144
114
  def modulate(modulo)
145
115
  if modulo == 1
146
116
  to_a
@@ -180,14 +150,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
180
150
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity
181
151
  # rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
182
152
 
183
- def pluck(*keys)
184
- if keys.many?
185
- map { |element| keys.map { |key| element[key] } }
186
- else
187
- map { |element| element[keys.first] }
188
- end
189
- end
190
-
191
153
  def produce(identity = 0, &block)
192
154
  if defined?(yield)
193
155
  map(&block).produce(identity)
@@ -248,5 +210,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
248
210
  end
249
211
  end
250
212
 
213
+ alias occurrences frequency
214
+
251
215
  end
252
216
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  if Lite::Ruby.configuration.monkey_patches.include?('hash')
4
+ require 'lite/ruby/safe/hash' unless defined?(ActiveSupport)
5
+
4
6
  class Hash
5
7
 
6
8
  class << self
@@ -161,39 +163,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
161
163
  replace(dearray_singular_values)
162
164
  end
163
165
 
164
- # rubocop:disable Style/CaseEquality
165
- def deep_dup
166
- hash = dup
167
-
168
- each_pair do |key, value|
169
- if key.frozen? && ::String === key
170
- hash[key] = value.deep_dup
171
- else
172
- hash.delete(key)
173
- hash[key.deep_dup] = value.deep_dup
174
- end
175
- end
176
-
177
- hash
178
- end
179
- # rubocop:enable Style/CaseEquality
180
-
181
- def deep_merge(other_hash, &block)
182
- dup.deep_merge!(other_hash, &block)
183
- end
184
-
185
- def deep_merge!(other_hash, &block)
186
- merge!(other_hash) do |key, this_val, other_val|
187
- if this_val.is_a?(Hash) && other_val.is_a?(Hash)
188
- this_val.deep_merge(other_val, &block)
189
- elsif defined?(yield)
190
- yield(key, this_val, other_val)
191
- else
192
- other_val
193
- end
194
- end
195
- end
196
-
197
166
  def delete_unless
198
167
  delete_if { |key, val| !yield(key, val) }
199
168
  end
@@ -232,18 +201,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
232
201
  h1.merge(h2)
233
202
  end
234
203
 
235
- def except(*keys)
236
- dup.except!(*keys)
237
- end
238
-
239
- def except!(*keys)
240
- keys.each_with_object(self) { |key, _| delete(key) }
241
- end
242
-
243
- def extract!(*keys)
244
- keys.each_with_object(self) { |key, hash| hash[key] = delete(key) if key?(key) }
245
- end
246
-
247
204
  def hmap(&block)
248
205
  dup.hmap!(&block)
249
206
  end
@@ -274,15 +231,15 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
274
231
  unknown_keys.empty?
275
232
  end
276
233
 
277
- alias has_keys? keys?
278
-
279
234
  def nillify
280
235
  dup.nillify!
281
236
  end
282
237
 
283
238
  def nillify!
284
239
  each do |key, val|
285
- self[key] = nil if !val.nil? && (val.try(:blank?) || val.try(:to_s).blank?)
240
+ next if val.nil?
241
+
242
+ self[key] = nil if respond_to?(:blank?) ? val.blank? : !val
286
243
  end
287
244
  end
288
245
 
@@ -299,8 +256,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
299
256
  unknown_keys.empty?
300
257
  end
301
258
 
302
- alias has_only_keys? only_keys?
303
-
304
259
  def pair?(key, value)
305
260
  self[key] == value
306
261
  end
@@ -324,14 +279,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
324
279
  keys.each_with_object(self) { |(key, val), hash| hash[val] = delete(key) if hash[key] }
325
280
  end
326
281
 
327
- def reverse_merge(other_hash)
328
- other_hash.merge(self)
329
- end
330
-
331
- def reverse_merge!(other_hash)
332
- replace(reverse_merge(other_hash))
333
- end
334
-
335
282
  def sample
336
283
  key = sample_key
337
284
  [key, fetch(key)]
@@ -349,7 +296,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
349
296
  end
350
297
 
351
298
  def sample_key!
352
- key, = sample
299
+ key, _val = sample
353
300
  delete(key)
354
301
  key
355
302
  end
@@ -381,52 +328,25 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
381
328
  omit
382
329
  end
383
330
 
384
- alias only slice
385
- alias only! slice!
386
-
387
- def stringify_keys
388
- each_with_object({}) { |(key, val), hash| hash[key.to_s] = val }
389
- end
390
-
391
- def stringify_keys!
392
- replace(stringify_keys)
393
- end
394
-
395
331
  def strip
396
- select { |_, val| !val.blank? }
332
+ reject { |_, val| respond_to?(:blank?) ? val.blank? : !val }
397
333
  end
398
334
 
399
335
  def strip!
400
- reject! { |_, val| val.blank? }
401
- end
402
-
403
- def symbolize_keys
404
- each_with_object({}) do |(key, val), hash|
405
- new_key = begin
406
- key.to_s.to_sym
407
- rescue StandardError
408
- key
409
- end
410
-
411
- hash[new_key] = val
412
- end
413
- end
414
-
415
- def symbolize_keys!
416
- replace(symbolize_keys)
336
+ reject! { |_, val| respond_to?(:blank?) ? val.blank? : !val }
417
337
  end
418
338
 
419
339
  # rubocop:disable Metrics/MethodLength
420
340
  def symbolize_and_underscore_keys
421
341
  each_with_object({}) do |(key, val), hash|
422
342
  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
343
+ str = key.dup.to_s
344
+ str = str.gsub!(/::/, '/') || str
345
+ str = str.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') || str
346
+ str = str.gsub!(/([a-z\d])([A-Z])/, '\1_\2') || str
347
+ str = str.tr!(' -', '_') || str
348
+ str = str.downcase!
349
+ str.to_sym
430
350
  rescue StandardError
431
351
  key
432
352
  end
@@ -444,8 +364,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
444
364
  JSON.parse(to_json, object_class: OpenStruct)
445
365
  end
446
366
 
447
- alias to_o to_object
448
-
449
367
  def to_open_struct(lazy: true)
450
368
  struct = OpenStruct.new(self)
451
369
  struct.methods(lazy)
@@ -478,5 +396,13 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
478
396
  respond_to?(:blank?) ? value.blank? : !value
479
397
  end
480
398
 
399
+ alias has_keys? keys?
400
+ alias has_only_keys? only_keys?
401
+ alias map_keys collect_keys
402
+ alias map_values collect_values
403
+ alias only slice
404
+ alias only! slice!
405
+ alias to_o to_object
406
+
481
407
  end
482
408
  end
@@ -9,9 +9,9 @@ if Lite::Ruby.configuration.monkey_patches.include?('time')
9
9
  hour: '%H',
10
10
  hour_blank: '%k',
11
11
  hour_padded: '%H',
12
- hour_12: '%I',
13
- hour_12_padded: '%I',
14
- hour_12_blank: '%l',
12
+ hour12: '%I',
13
+ hour12_padded: '%I',
14
+ hour12_blank: '%l',
15
15
  minute: '%M',
16
16
  second: '%S',
17
17
  ampm: '%P',
@@ -25,29 +25,29 @@ if Lite::Ruby.configuration.monkey_patches.include?('time')
25
25
  time_padded: '%H:%M',
26
26
  time_tz: '%H:%M %z',
27
27
  time_tzn: '%H:%M %Z',
28
- time_12: '%I:%M %P',
29
- time_12_padded: '%I:%M %P',
30
- time_12_blank: '%l:%M %P',
31
- time_12_tz: '%I:%M %P %z',
32
- time_12_tzn: '%I:%M %P %Z',
28
+ time12: '%I:%M %P',
29
+ time12_padded: '%I:%M %P',
30
+ time12_blank: '%l:%M %P',
31
+ time12_tz: '%I:%M %P %z',
32
+ time12_tzn: '%I:%M %P %Z',
33
33
  daytime: '%B %-d %H:%M',
34
34
  daytime_abbr: '%b %-d %H:%M',
35
35
  daytime_iso: '%m-%d %H:%M',
36
- daytime_12: '%B %-d %I:%M %P',
37
- daytime_12_abbr: '%b %-d %I:%M %P',
38
- daytime_12_iso: '%m-%d %I:%M %P',
36
+ daytime12: '%B %-d %I:%M %P',
37
+ daytime12_abbr: '%b %-d %I:%M %P',
38
+ daytime12_iso: '%m-%d %I:%M %P',
39
39
  datetime: '%B %-d, %Y %H:%M',
40
40
  datetime_abbr: '%b %-d, %Y %H:%M',
41
41
  datetime_iso: '%Y-%m-%d %H:%M',
42
- datetime_12: '%B %-d, %Y %I:%M %P',
43
- datetime_12_abbr: '%b %-d, %Y %I:%M %P',
44
- datetime_12_iso: '%Y-%m-%d %I:%M %P',
42
+ datetime12: '%B %-d, %Y %I:%M %P',
43
+ datetime12_abbr: '%b %-d, %Y %I:%M %P',
44
+ datetime12_iso: '%Y-%m-%d %I:%M %P',
45
45
  datetime_tzn: '%B %-d, %Y %H:%M %Z',
46
46
  datetime_abbr_tzn: '%b %-d, %Y %H:%M %Z',
47
47
  datetime_iso_tzn: '%Y-%m-%d %H:%M %z',
48
- datetime_12_tzn: '%B %-d, %Y %I:%M %P %Z',
49
- datetime_12_abbr_tzn: '%b %-d, %Y %I:%M %P %Z',
50
- datetime_12_iso_tzn: '%Y-%m-%d %I:%M %P %z'
48
+ datetime12_tzn: '%B %-d, %Y %I:%M %P %Z',
49
+ datetime12_abbr_tzn: '%b %-d, %Y %I:%M %P %Z',
50
+ datetime12_iso_tzn: '%Y-%m-%d %I:%M %P %z'
51
51
  }.freeze
52
52
  TIME_UNITS = {
53
53
  h: 'H',
@@ -57,11 +57,11 @@ if Lite::Ruby.configuration.monkey_patches.include?('time')
57
57
  HOUR: 'k',
58
58
  hour_blank: 'k',
59
59
  hhh: 'I',
60
- hour_12: 'I',
61
- hour_12_padded: 'I',
60
+ hour12: 'I',
61
+ hour12_padded: 'I',
62
62
  hhhh: 'l',
63
- HOUR_12: 'l',
64
- hour_12_blank: 'l',
63
+ HOUR12: 'l',
64
+ hour12_blank: 'l',
65
65
  n: 'M',
66
66
  minute: 'M',
67
67
  s: 'S',
@@ -15,23 +15,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
15
15
  self <= upper ? self : upper
16
16
  end
17
17
 
18
- # rubocop:disable Metrics/MethodLength
19
- def clamp(minimum, maximum = nil)
20
- if minimum.is_a?(Range)
21
- maximum = minimum.max
22
- minimum = minimum.min
23
- end
24
-
25
- if minimum > self
26
- minimum
27
- elsif maximum < self
28
- maximum
29
- else
30
- self
31
- end
32
- end
33
- # rubocop:enable Metrics/MethodLength
34
-
35
18
  def close?(number, epsilon = 0.01)
36
19
  return self == number if epsilon.zero?
37
20
 
@@ -79,8 +62,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
79
62
  self == num
80
63
  end
81
64
 
82
- alias eq? equal_to?
83
-
84
65
  def fraction
85
66
  (self - truncate).abs
86
67
  end
@@ -93,14 +74,10 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
93
74
  num < self
94
75
  end
95
76
 
96
- alias gt? greater_than?
97
-
98
77
  def greater_than_or_equal_to?(num)
99
78
  num <= self
100
79
  end
101
80
 
102
- alias gteq? greater_than_or_equal_to?
103
-
104
81
  def increment(amount = 1.0)
105
82
  self + amount
106
83
  end
@@ -113,14 +90,10 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
113
90
  num > self
114
91
  end
115
92
 
116
- alias lt? less_than?
117
-
118
93
  def less_than_or_equal_to?(num)
119
94
  num >= self
120
95
  end
121
96
 
122
- alias lteq? less_than_or_equal_to?
123
-
124
97
  def markdown_percentage(percent)
125
98
  to_f * ((100.0 - percent.to_f) / 100.0)
126
99
  end
@@ -143,10 +116,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
143
116
  self != num
144
117
  end
145
118
 
146
- alias not_eq? not_equal_to?
147
- alias inequal_to? not_equal_to?
148
- alias ineq? not_equal_to?
149
-
150
119
  def ordinal
151
120
  return 'th' if (11..13).cover?(abs % 100)
152
121
 
@@ -206,8 +175,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
206
175
  (self - value)..(self + value)
207
176
  end
208
177
 
209
- alias plus_minus range
210
-
211
178
  def root(num)
212
179
  self**(1.0 / num)
213
180
  end
@@ -263,5 +230,15 @@ if Lite::Ruby.configuration.monkey_patches.include?('numeric')
263
230
  end
264
231
  end
265
232
 
233
+ alias eq? equal_to?
234
+ alias gt? greater_than?
235
+ alias gteq? greater_than_or_equal_to?
236
+ alias inequal_to? not_equal_to?
237
+ alias ineq? not_equal_to?
238
+ alias lt? less_than?
239
+ alias lteq? less_than_or_equal_to?
240
+ alias not_eq? not_equal_to?
241
+ alias plus_minus range
242
+
266
243
  end
267
244
  end