lite-ruby 1.1.8 → 1.1.13

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: b5cc9dd9687e74df36b99aef11ca0b804161e5bf63b96872e1aa04974127c0fe
4
- data.tar.gz: 784f195955ead892563a881ecccbb548f5faf95057c12408c7f94619a9fe182a
3
+ metadata.gz: fe679570639cc347f06cb66cb3cefab5f43c76d66d2460050f91a9f2107a9baf
4
+ data.tar.gz: 9c342175047a4783844895e1fce5759d0351d6ed15383a5c245700637408af3b
5
5
  SHA512:
6
- metadata.gz: '093d15a0c4579fcd4230de82edf2d78975a30b12e7e9a63ea2d7d0cc29832a019add61192eea7a6bcb65c6018d22e411cb2bee6dcee4bc169da5b3f5063a80be'
7
- data.tar.gz: 8ddcdfdd7059f5cb9d54b64f4598b9dc0747e9f3d8f1e49c865b4477369cad0c414ac89be4eb9e7d87b4e9d9a04d75de745fd61fef71c8defd880bf566e85a56
6
+ metadata.gz: 51c1075b41fee9f7c36a6530e31caa46fe1edbdc3779708485c3f4d6d9f0ea2c16bd31e282414926fa1d1962d69fd75920144a4c9dbb66c2b7a65f43af316e3d
7
+ data.tar.gz: 360692b781b2e8eaa7d511a1c225fe6721a241673fe670eaa682056d96379448a622c4cc3abe0a30c3350c9411d6aea3ae58084e821f79cdd5039b0479d51a7a
data/CHANGELOG.md CHANGED
@@ -6,6 +6,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.13] - 2021-07-05
10
+ ### Added
11
+ - Added more OpenStruct backwards compatibility
12
+
13
+ ## [1.1.12] - 2021-07-05
14
+ ### Added
15
+ - Added OpenStruct backwards compatibility
16
+
17
+ ## [1.1.11] - 2021-07-04
18
+ ### Added
19
+ - Added Array => `contains_all?`
20
+ - Added Array => `contains_any?`
21
+ - Added Array => `contains_none?`
22
+
23
+ ## [1.1.10] - 2021-06-21
24
+ ### Changed
25
+ - Struct `[]` to be accessible via `attributes`
26
+ ### Removed
27
+ - OpenStruct `[]` and `[]=` existing methods
28
+
29
+ ## [1.1.9] - 2021-05-26
30
+ ### Added
31
+ - Added Array => `match`
32
+ - Added Array => `strip` to `compact_blank` alias
33
+ - Added Enumerable => `pick`
34
+ ### Changed
35
+ - Move safe requires to bottom of file
36
+
9
37
  ## [1.1.8] - 2021-07-05
10
38
  ### Changed
11
39
  - Linter fixes
data/Gemfile.lock CHANGED
@@ -1,25 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.1.8)
4
+ lite-ruby (1.1.13)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- actionpack (6.1.3.2)
10
- actionview (= 6.1.3.2)
11
- activesupport (= 6.1.3.2)
9
+ actionpack (6.1.4)
10
+ actionview (= 6.1.4)
11
+ activesupport (= 6.1.4)
12
12
  rack (~> 2.0, >= 2.0.9)
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.1.3.2)
17
- activesupport (= 6.1.3.2)
16
+ actionview (6.1.4)
17
+ activesupport (= 6.1.4)
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.1.3.2)
22
+ activesupport (6.1.4)
23
23
  concurrent-ruby (~> 1.0, >= 1.0.2)
24
24
  i18n (>= 1.6, < 2)
25
25
  minitest (>= 5.1)
@@ -28,7 +28,7 @@ GEM
28
28
  ast (2.4.2)
29
29
  builder (3.2.4)
30
30
  colorize (0.8.1)
31
- concurrent-ruby (1.1.8)
31
+ concurrent-ruby (1.1.9)
32
32
  crass (1.0.6)
33
33
  diff-lcs (1.4.4)
34
34
  erubi (1.10.0)
@@ -40,13 +40,13 @@ GEM
40
40
  railties (>= 3.0.0)
41
41
  i18n (1.8.10)
42
42
  concurrent-ruby (~> 1.0)
43
- loofah (2.9.1)
43
+ loofah (2.10.0)
44
44
  crass (~> 1.0.2)
45
45
  nokogiri (>= 1.5.9)
46
46
  method_source (1.0.0)
47
- mini_portile2 (2.5.1)
47
+ mini_portile2 (2.5.3)
48
48
  minitest (5.14.4)
49
- nokogiri (1.11.3)
49
+ nokogiri (1.11.7)
50
50
  mini_portile2 (~> 2.5.0)
51
51
  racc (~> 1.4)
52
52
  parallel (1.20.1)
@@ -61,11 +61,11 @@ GEM
61
61
  nokogiri (>= 1.6)
62
62
  rails-html-sanitizer (1.3.0)
63
63
  loofah (~> 2.3)
64
- railties (6.1.3.2)
65
- actionpack (= 6.1.3.2)
66
- activesupport (= 6.1.3.2)
64
+ railties (6.1.4)
65
+ actionpack (= 6.1.4)
66
+ activesupport (= 6.1.4)
67
67
  method_source
68
- rake (>= 0.8.7)
68
+ rake (>= 0.13)
69
69
  thor (~> 1.0)
70
70
  rainbow (3.0.0)
71
71
  rake (13.0.3)
@@ -84,29 +84,29 @@ GEM
84
84
  diff-lcs (>= 1.2.0, < 2.0)
85
85
  rspec-support (~> 3.10.0)
86
86
  rspec-support (3.10.2)
87
- rubocop (1.14.0)
87
+ rubocop (1.18.2)
88
88
  parallel (~> 1.10)
89
89
  parser (>= 3.0.0.0)
90
90
  rainbow (>= 2.2.2, < 4.0)
91
91
  regexp_parser (>= 1.8, < 3.0)
92
92
  rexml
93
- rubocop-ast (>= 1.5.0, < 2.0)
93
+ rubocop-ast (>= 1.7.0, < 2.0)
94
94
  ruby-progressbar (~> 1.7)
95
95
  unicode-display_width (>= 1.4.0, < 3.0)
96
- rubocop-ast (1.5.0)
96
+ rubocop-ast (1.7.0)
97
97
  parser (>= 3.0.1.1)
98
98
  rubocop-performance (1.11.3)
99
99
  rubocop (>= 1.7.0, < 2.0)
100
100
  rubocop-ast (>= 0.4.0)
101
- rubocop-rake (0.5.1)
102
- rubocop
103
- rubocop-rspec (2.3.0)
101
+ rubocop-rake (0.6.0)
102
+ rubocop (~> 1.0)
103
+ rubocop-rspec (2.4.0)
104
104
  rubocop (~> 1.0)
105
105
  rubocop-ast (>= 1.1.0)
106
106
  ruby-progressbar (1.11.0)
107
- ruby_parser (3.15.1)
108
- sexp_processor (~> 4.9)
109
- sexp_processor (4.15.2)
107
+ ruby_parser (3.16.0)
108
+ sexp_processor (~> 4.15, >= 4.15.1)
109
+ sexp_processor (4.15.3)
110
110
  thor (1.1.0)
111
111
  tzinfo (2.0.4)
112
112
  concurrent-ruby (~> 1.0)
@@ -129,4 +129,4 @@ DEPENDENCIES
129
129
  rubocop-rspec
130
130
 
131
131
  BUNDLED WITH
132
- 2.2.17
132
+ 2.2.19
data/docs/ARRAY.md CHANGED
@@ -104,6 +104,39 @@ Updates a deeply nested value.
104
104
  ['1', ['2']].bury(1) #=> raises ArgumentError: '2 or more arguments required'
105
105
  ```
106
106
 
107
+ `contains_all?`
108
+ ------
109
+ Returns true/false if an array contains all values from another.
110
+
111
+ ```ruby
112
+ [1, 2, 3].contains_all?([1, 2, 3]) #=> true
113
+ [1, 2, 3].contains_all?([1, 2, 3, 4]) #=> true
114
+ [1, 2, 3].contains_all?([1, 2]) #=> false
115
+ [1, 2, 3].contains_all?([4, 5]) #=> false
116
+ ```
117
+
118
+ `contains_any?`
119
+ ------
120
+ Returns true/false if an array contains any values from another.
121
+
122
+ ```ruby
123
+ [1, 2, 3].contains_any?([1, 2]) #=> true
124
+ [1, 2, 3].contains_any?([1, 2, 3]) #=> true
125
+ [1, 2, 3].contains_any?([1, 2, 3, 4]) #=> true
126
+ [1, 2, 3].contains_any?([4, 5]) #=> false
127
+ ```
128
+
129
+ `contains_none?`
130
+ ------
131
+ Returns true/false if an array contains none of the values from another.
132
+
133
+ ```ruby
134
+ [1, 2, 3].contains_none?([4, 5]) #=> true
135
+ [1, 2, 3].contains_none?([1, 2]) #=> false
136
+ [1, 2, 3].contains_none?([1, 2, 3]) #=> false
137
+ [1, 2, 3].contains_none?([1, 2, 3, 4]) #=> false
138
+ ```
139
+
107
140
  `delete_first(!)`
108
141
  ------
109
142
  Removes the first element from an array. Like `shift`, but returns the array instead of the removed element.
@@ -235,6 +268,15 @@ Returns all indexes of the matching value.
235
268
  [:a,:b,:a,:c].indexes(:a) #=> [0, 2]
236
269
  ```
237
270
 
271
+ `match`
272
+ ------
273
+ Select a given value from the array.
274
+
275
+ ```ruby
276
+ [1, 2, 3, 4].match(1) #=> 1
277
+ [1, 2, 3, 4].match(9) #=> nil
278
+ ```
279
+
238
280
  `merge(!)`
239
281
  ------
240
282
  Concats multiple arrays.
@@ -259,6 +301,7 @@ Selects given values from the array.
259
301
 
260
302
  ```ruby
261
303
  [1, 2, 3, 4].only(1, 3) #=> [1, 3]
304
+ [1, 2, 3, 4].only!(8, 9) #=> []
262
305
  ```
263
306
 
264
307
  `probability`
@@ -328,7 +371,7 @@ Divides the array into one or more subarrays based on a delimiting value or the
328
371
  (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
329
372
  ```
330
373
 
331
- `strip(!)`
374
+ `strip(!)` aka `compact_blank(!)`
332
375
  ------
333
376
  Removes blank elements from an array.
334
377
 
data/docs/ENUMERABLE.md CHANGED
@@ -158,6 +158,18 @@ a1.occur(2..3) #=> [1,3,5]
158
158
  a1.occur { |n| n > 1 } #=> [1,3,5]
159
159
  ```
160
160
 
161
+ `pick`
162
+ ------
163
+ Returns a value from a set of given keys.
164
+
165
+ ```ruby
166
+ a1 = [{ id: 1, name: 'a' }, { id: 2, name: 'b' }]
167
+
168
+ a1.pick(:id) #=> 1
169
+ a1.pick(:id, :name) #=> [1,'a']
170
+ a1.pick(:fake) #=> nil
171
+ ```
172
+
161
173
  `pluck`
162
174
  ------
163
175
  Returns an array of values from a set of given keys.
@@ -167,6 +179,7 @@ a1 = [{ id: 1, name: 'a' }, { id: 2, name: 'b' }]
167
179
 
168
180
  a1.pluck(:id) #=> [1,2]
169
181
  a1.pluck(:id, :name) #=> [[1,'a'], [2,'b']]
182
+ a1.pluck(:fake) #=> [nil,nil]
170
183
  ```
171
184
 
172
185
  `produce`
data/docs/OPEN_STRUCT.md CHANGED
@@ -9,26 +9,6 @@ OpenStruct.new(name: 'bob', age: 60) do |o|
9
9
  end
10
10
  ```
11
11
 
12
- `[]`
13
- ------
14
- Access a value in the OpenStruct by key, like a Hash.
15
-
16
- ```ruby
17
- person = OpenStruct.new(name: 'bob', age: 60)
18
-
19
- person['name'] #=> 'bob'
20
- ```
21
-
22
- `[]=`
23
- ------
24
- Store a value in the OpenStruct by key, like a Hash.
25
-
26
- ```ruby
27
- person = OpenStruct.new(name: 'bob', age: 60)
28
-
29
- person['name'] = 'tim'
30
- ```
31
-
32
12
  `attributes`
33
13
  ------
34
14
  Returns the key values as a hash of the assigned struct.
data/docs/STRING.md CHANGED
@@ -240,9 +240,9 @@ of the string until it reaches the limit value (counting backwards). If the give
240
240
  than or equal to the string length, Returns a copy of self.
241
241
 
242
242
  ```ruby
243
- 'example'.last #=> 'e'
244
- 'example'.last(0) #=> ''
245
- 'example'.first(3) #=> 'ple'
243
+ 'example'.last #=> 'e'
244
+ 'example'.last(0) #=> ''
245
+ 'example'.last(3) #=> 'ple'
246
246
  ```
247
247
 
248
248
  `lchomp(!)`
data/docs/STRUCT.md CHANGED
@@ -9,6 +9,7 @@ person = Struct.new(:name, :age)
9
9
  person.new('bob', 60)
10
10
 
11
11
  person['name'] #=> 'bob'
12
+ person['fake'] #=> nil
12
13
  ```
13
14
 
14
15
  `[]=`
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  if Lite::Ruby.configuration.monkey_patches.include?('array')
4
- require 'lite/ruby/safe/array' unless defined?(ActiveSupport)
5
-
6
4
  class Array
7
5
 
8
6
  def assert_min_values!(*valid_values)
@@ -111,6 +109,18 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
111
109
  # rubocop:enable Metrics/PerceivedComplexity, Style/GuardClause, Style/IfInsideElse
112
110
  # rubocop:enable Metrics/AbcSize, Metrics/BlockNesting, Metrics/MethodLength
113
111
 
112
+ def contains_all?(other)
113
+ (other & self) == self
114
+ end
115
+
116
+ def contains_any?(other)
117
+ !contains_none?(other)
118
+ end
119
+
120
+ def contains_none?(other)
121
+ (other & self).empty?
122
+ end
123
+
114
124
  def delete_first
115
125
  self[1..-1]
116
126
  end
@@ -188,6 +198,10 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
188
198
  array
189
199
  end
190
200
 
201
+ def match(value)
202
+ find { |val| value == val }
203
+ end
204
+
191
205
  def merge(*values)
192
206
  dup.merge!(*values)
193
207
  end
@@ -282,4 +296,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
282
296
  alias select_values! only!
283
297
 
284
298
  end
299
+
300
+ require 'lite/ruby/safe/array' unless defined?(ActiveSupport)
285
301
  end
@@ -1,8 +1,6 @@
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
-
6
4
  module Enumerable
7
5
 
8
6
  def cluster
@@ -209,4 +207,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('enumerable')
209
207
  alias occurrences frequency
210
208
 
211
209
  end
210
+
211
+ require 'lite/ruby/safe/enumerable' unless defined?(ActiveSupport)
212
212
  end
@@ -1,8 +1,6 @@
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
-
6
4
  class Hash
7
5
 
8
6
  class << self
@@ -405,4 +403,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
405
403
  alias to_o to_object
406
404
 
407
405
  end
406
+
407
+ require 'lite/ruby/safe/hash' unless defined?(ActiveSupport)
408
408
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  if Lite::Ruby.configuration.monkey_patches.include?('object')
4
- require 'lite/ruby/safe/object' unless defined?(ActiveSupport)
5
-
6
4
  class Object
7
5
 
8
6
  FALSE_VALUES = %w[
@@ -168,4 +166,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
168
166
  alias to_b to_bool
169
167
 
170
168
  end
169
+
170
+ require 'lite/ruby/safe/object' unless defined?(ActiveSupport)
171
171
  end
@@ -20,24 +20,12 @@ if Lite::Ruby.configuration.monkey_patches.include?('open_struct')
20
20
  yield self if block && block.arity == 1
21
21
  end
22
22
 
23
- def [](key)
24
- key = key.to_sym unless key.is_a?(Symbol)
25
- @table[key]
26
- end
27
-
28
- def []=(key, val)
29
- raise TypeError, "can't modify frozen #{self.class}", caller(1) if frozen?
30
-
31
- key = key.to_sym unless key.is_a?(Symbol)
32
- @table[key] = val
33
- end
34
-
35
23
  def attributes
36
24
  @table
37
25
  end
38
26
 
39
27
  def replace(args)
40
- args.each_pair { |key, val| send("#{key}=", val) }
28
+ args.each { |key, val| send("#{key}=", val) }
41
29
  end
42
30
 
43
31
  def to_hash(table: true)
@@ -53,5 +41,38 @@ if Lite::Ruby.configuration.monkey_patches.include?('open_struct')
53
41
  alias as_json to_json
54
42
  alias to_h to_hash
55
43
 
44
+ private
45
+
46
+ # rubocop:disable Metrics/MethodLength, Naming/PredicateName
47
+ def is_method_protected!(name)
48
+ return false unless respond_to?(name, true)
49
+ return true if name.match?(/!$/)
50
+
51
+ owner = method!(name).owner
52
+
53
+ if owner.instance_of?(::Class)
54
+ owner < ::OpenStruct
55
+ else
56
+ self.class.ancestors.any? do |mod|
57
+ return false if mod == ::OpenStruct
58
+
59
+ mod == owner
60
+ end
61
+ end
62
+ end
63
+ # rubocop:enable Metrics/MethodLength, Naming/PredicateName
64
+
65
+ def new_ostruct_member!(name)
66
+ return if is_method_protected!(name)
67
+
68
+ if respond_to?(:define_singleton_method!)
69
+ define_singleton_method(name) { @table[name] }
70
+ define_singleton_method("#{name}=") { |x| @table[name] = x }
71
+ else
72
+ define_singleton_method!(name) { @table[name] }
73
+ define_singleton_method!("#{name}=") { |x| @table[name] = x }
74
+ end
75
+ end
76
+
56
77
  end
57
78
  end
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  if Lite::Ruby.configuration.monkey_patches.include?('range')
4
- require 'lite/ruby/safe/range' unless defined?(ActiveSupport)
5
-
6
4
  class Range
7
5
 
8
6
  def combine(other)
@@ -29,4 +27,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('range')
29
27
  end
30
28
 
31
29
  end
30
+
31
+ require 'lite/ruby/safe/range' unless defined?(ActiveSupport)
32
32
  end
@@ -98,4 +98,7 @@ class Array
98
98
  end
99
99
  end
100
100
 
101
+ alias compact_blank strip
102
+ alias compact_blank! strip!
103
+
101
104
  end
@@ -28,11 +28,22 @@ module Enumerable
28
28
  end
29
29
  end
30
30
 
31
+ def pick(*keys)
32
+ return if none?
33
+
34
+ if keys.many?
35
+ keys.map { |key| first[key] }
36
+ else
37
+ first[keys.first]
38
+ end
39
+ end
40
+
31
41
  def pluck(*keys)
32
42
  if keys.many?
33
43
  map { |element| keys.map { |key| element[key] } }
34
44
  else
35
- map { |element| element[keys.first] }
45
+ key = keys.first
46
+ map { |element| element[key] }
36
47
  end
37
48
  end
38
49
 
@@ -1,8 +1,6 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  if Lite::Ruby.configuration.monkey_patches.include?('string')
4
- require 'lite/ruby/safe/string' unless defined?(ActiveSupport)
5
-
6
4
  class String
7
5
 
8
6
  TRANSLITERATIONS = {
@@ -482,4 +480,6 @@ if Lite::Ruby.configuration.monkey_patches.include?('string')
482
480
  alias titlecase! titleize!
483
481
 
484
482
  end
483
+
484
+ require 'lite/ruby/safe/string' unless defined?(ActiveSupport)
485
485
  end
@@ -4,7 +4,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('struct')
4
4
  class Struct
5
5
 
6
6
  def [](key)
7
- send(key)
7
+ attributes[key.to_sym]
8
8
  end
9
9
 
10
10
  def []=(key, val)
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION = '1.1.8'
6
+ VERSION = '1.1.13'
7
7
 
8
8
  end
9
9
  end
data/lite-ruby.gemspec CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  )
26
26
  else
27
27
  raise 'RubyGems 2.0 or newer is required to protect against ' \
28
- 'public gem pushes.'
28
+ 'public gem pushes.'
29
29
  end
30
30
 
31
31
  # Specify which files should be added to the gem when it is released.
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.1.8
4
+ version: 1.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-07 00:00:00.000000000 Z
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -222,7 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
224
  requirements: []
225
- rubygems_version: 3.2.17
225
+ rubygems_version: 3.2.19
226
226
  signing_key:
227
227
  specification_version: 4
228
228
  summary: Collection of useful Ruby methods for its primitive classes