lite-ruby 1.1.9 → 1.1.14
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -0
- data/Gemfile.lock +22 -22
- data/docs/ARRAY.md +33 -0
- data/docs/OPEN_STRUCT.md +0 -20
- data/docs/STRING.md +3 -3
- data/docs/STRUCT.md +1 -0
- data/lib/lite/ruby/array.rb +12 -0
- data/lib/lite/ruby/open_struct.rb +32 -13
- data/lib/lite/ruby/struct.rb +1 -1
- data/lib/lite/ruby/version.rb +1 -1
- data/lite-ruby.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff28b7935f151e1b0b380b88a846a43d5c26fd0ed8f0ec3868d8766c906d7a86
|
4
|
+
data.tar.gz: 44d6ba04ae35be6ccc79030b8cf818cf7c073962619190e11ac0082146650e7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db466696e81b718156b43a0e9ae3f78f0c5c0dfd960b53fc34aaf4ef393be7b5aef9bf31acbb13d9612be1c9305c4bcc43aa4996f19bf3776ce57cbc38448238
|
7
|
+
data.tar.gz: cec62b1c8ab6f99e88cc9d775d91411543ea016e9f40ea4c2c3d5fac7a8770bd5f985cf1a598c8a0c4a4a1b1505ae06d8dbda75ea3e3361b3a7ac5f01acf4307
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,30 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.1.14] - 2021-07-05
|
10
|
+
### Changed
|
11
|
+
- Fixed mistake in OpenStruct backwards compatibility
|
12
|
+
|
13
|
+
## [1.1.13] - 2021-07-05
|
14
|
+
### Added
|
15
|
+
- Added more OpenStruct backwards compatibility
|
16
|
+
|
17
|
+
## [1.1.12] - 2021-07-05
|
18
|
+
### Added
|
19
|
+
- Added OpenStruct backwards compatibility
|
20
|
+
|
21
|
+
## [1.1.11] - 2021-07-04
|
22
|
+
### Added
|
23
|
+
- Added Array => `contains_all?`
|
24
|
+
- Added Array => `contains_any?`
|
25
|
+
- Added Array => `contains_none?`
|
26
|
+
|
27
|
+
## [1.1.10] - 2021-06-21
|
28
|
+
### Changed
|
29
|
+
- Struct `[]` to be accessible via `attributes`
|
30
|
+
### Removed
|
31
|
+
- OpenStruct `[]` and `[]=` existing methods
|
32
|
+
|
9
33
|
## [1.1.9] - 2021-05-26
|
10
34
|
### Added
|
11
35
|
- Added Array => `match`
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-ruby (1.1.
|
4
|
+
lite-ruby (1.1.14)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
actionpack (6.1.
|
10
|
-
actionview (= 6.1.
|
11
|
-
activesupport (= 6.1.
|
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.
|
17
|
-
activesupport (= 6.1.
|
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.
|
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.
|
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.
|
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.
|
47
|
+
mini_portile2 (2.5.3)
|
48
48
|
minitest (5.14.4)
|
49
|
-
nokogiri (1.11.
|
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.
|
65
|
-
actionpack (= 6.1.
|
66
|
-
activesupport (= 6.1.
|
64
|
+
railties (6.1.4)
|
65
|
+
actionpack (= 6.1.4)
|
66
|
+
activesupport (= 6.1.4)
|
67
67
|
method_source
|
68
|
-
rake (>= 0.
|
68
|
+
rake (>= 0.13)
|
69
69
|
thor (~> 1.0)
|
70
70
|
rainbow (3.0.0)
|
71
71
|
rake (13.0.3)
|
@@ -84,23 +84,23 @@ 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.
|
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.
|
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.
|
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.
|
102
|
-
rubocop
|
103
|
-
rubocop-rspec (2.
|
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)
|
@@ -129,4 +129,4 @@ DEPENDENCIES
|
|
129
129
|
rubocop-rspec
|
130
130
|
|
131
131
|
BUNDLED WITH
|
132
|
-
2.2.
|
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.
|
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
|
244
|
-
'example'.last(0)
|
245
|
-
'example'.
|
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
data/lib/lite/ruby/array.rb
CHANGED
@@ -109,6 +109,18 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
|
|
109
109
|
# rubocop:enable Metrics/PerceivedComplexity, Style/GuardClause, Style/IfInsideElse
|
110
110
|
# rubocop:enable Metrics/AbcSize, Metrics/BlockNesting, Metrics/MethodLength
|
111
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
|
+
|
112
124
|
def delete_first
|
113
125
|
self[1..-1]
|
114
126
|
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.
|
28
|
+
args.each { |key, val| send("#{key}=", val) }
|
41
29
|
end
|
42
30
|
|
43
31
|
def to_hash(table: true)
|
@@ -53,5 +41,36 @@ 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
|
+
method = 'define_singleton_method'
|
69
|
+
method << '!' if respond_to?(:define_singleton_method!)
|
70
|
+
|
71
|
+
send(method, name) { @table[name] }
|
72
|
+
send(method, "#{name}=") { |x| @table[name] = x }
|
73
|
+
end
|
74
|
+
|
56
75
|
end
|
57
76
|
end
|
data/lib/lite/ruby/struct.rb
CHANGED
data/lib/lite/ruby/version.rb
CHANGED
data/lite-ruby.gemspec
CHANGED
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.
|
4
|
+
version: 1.1.14
|
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
|
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.
|
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
|