lite-ruby 1.0.18 → 1.0.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/docs/ARRAY.md +21 -3
- data/docs/HASH.md +18 -0
- data/lib/lite/ruby/array.rb +21 -1
- data/lib/lite/ruby/hash.rb +23 -3
- data/lib/lite/ruby/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b62cca1155994d26807711ee316fea8f1b34f3669decacd5345c77662ea1cbc8
|
4
|
+
data.tar.gz: 57d062e524a7a4b208a05748b06e86d5b9a5c9b68874ecb8135f86e3e8560aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e11837df013186190c43feae3712be25a4bc286ac975b50219771ed055b0848501c5753759f81cc2e2ae288966a6b594b983b7d5f25101add2eeab57e6a4cf7f
|
7
|
+
data.tar.gz: e4ea9ea29831381e7e363fde4b4a98129e42a00284bcbbd4fc9ede53bb48b0c4118c99f337b00d69b6f9bde344ec48038d1896cc3f8ec09c53064cab29c5673b
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.0.19] - 2019-09-03
|
10
|
+
### Added
|
11
|
+
- Added Array => `assert_min_values!`
|
12
|
+
- Added Array => `assert_all_min_values!`
|
13
|
+
- Added Hash => `assert_min_keys!`
|
14
|
+
- Added Hash => `assert_all_min_keys!`
|
15
|
+
|
9
16
|
## [1.0.18] - 2019-09-03
|
10
17
|
### Added
|
11
18
|
- Added Array => `assert_valid_values!`
|
data/Gemfile.lock
CHANGED
data/docs/ARRAY.md
CHANGED
@@ -1,13 +1,31 @@
|
|
1
1
|
# Array
|
2
2
|
|
3
|
+
`assert_min_values!`
|
4
|
+
------
|
5
|
+
Raises an error if at least one value is not included in a list of values.
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
[].assert_min_values!(:foo) #=> []
|
9
|
+
[:foo, :bar].assert_min_values!(:foo) #=> [:foo]
|
10
|
+
[:baz, :bar].assert_min_values!(:foo, :boo) #=> raises ArgumentError: 'Missing value: ":foo". Minimum values are: ":foo", ":boo"'
|
11
|
+
```
|
12
|
+
|
13
|
+
`assert_all_min_values!`
|
14
|
+
------
|
15
|
+
Raises an error like `assert_min_values!` but also on empty.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
[].assert_all_min_values!(:foo) #=> raises ArgumentError: 'An empty array is not allowed'
|
19
|
+
```
|
20
|
+
|
3
21
|
`assert_valid_values!`
|
4
22
|
------
|
5
23
|
Raises an error if value is not included in a list of values.
|
6
24
|
|
7
25
|
```ruby
|
8
26
|
[].assert_valid_values!(:foo) #=> []
|
9
|
-
[:foo].assert_valid_values!(:foo) #=>
|
10
|
-
[:foo, :bar].assert_valid_values!(:foo, :boo) #=> raises ArgumentError: 'Invalid value: ":
|
27
|
+
[:foo].assert_valid_values!(:foo) #=> [:foo]
|
28
|
+
[:foo, :bar].assert_valid_values!(:foo, :boo) #=> raises ArgumentError: 'Invalid value: ":bar". Allowed values are: ":foo", ":boo"'
|
11
29
|
```
|
12
30
|
|
13
31
|
`assert_all_valid_values!`
|
@@ -24,7 +42,7 @@ Raises an error if value is not `present?` or is nil.
|
|
24
42
|
|
25
43
|
```ruby
|
26
44
|
[].assert_value_presence! #=> []
|
27
|
-
[:foo].assert_value_presence! #=>
|
45
|
+
[:foo].assert_value_presence! #=> [:foo]
|
28
46
|
[nil].assert_value_presence! #=> raises ArgumentError: 'A 'nil' value is not allowed'
|
29
47
|
```
|
30
48
|
|
data/docs/HASH.md
CHANGED
@@ -19,6 +19,24 @@ h1.aka('boo', :foo)
|
|
19
19
|
h1['boo'] #=> 'bar'
|
20
20
|
```
|
21
21
|
|
22
|
+
`assert_min_keys!`
|
23
|
+
------
|
24
|
+
Raises an error if at least one key is not included in a list of keys.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
{}.assert_min_keys!(:foo) #=> {}
|
28
|
+
{ foo: 'bar', bar: 'baz' }.assert_min_keys!(:foo) #=> { foo: 'bar', bar: 'baz' }
|
29
|
+
{ baz: 'boz', bum: 'baz' }.assert_min_keys!(:foo, :boo) #=> raises ArgumentError: 'Missing key: ":foo". Minimum keys are: ":foo", ":boo"'
|
30
|
+
```
|
31
|
+
|
32
|
+
`assert_all_min_keys!`
|
33
|
+
------
|
34
|
+
Raises an error like `assert_min_values!` but also on empty.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
{}.assert_all_min_keys!(:foo) #=> raises ArgumentError: 'An empty hash is not allowed'
|
38
|
+
```
|
39
|
+
|
22
40
|
`assert_pair_presence!`
|
23
41
|
------
|
24
42
|
Raises an error if key is not included in a list of keys or if value is `blank?` or nil.
|
data/lib/lite/ruby/array.rb
CHANGED
@@ -3,12 +3,32 @@
|
|
3
3
|
if Lite::Ruby.configuration.monkey_patches.include?('array')
|
4
4
|
class Array
|
5
5
|
|
6
|
+
def assert_min_values!(*valid_values)
|
7
|
+
return self if empty?
|
8
|
+
|
9
|
+
valid_values.each do |value|
|
10
|
+
next if include?(value)
|
11
|
+
|
12
|
+
raise ArgumentError,
|
13
|
+
"Missing value: #{value.inspect}. " \
|
14
|
+
"Minimum values are: #{valid_values.map(&:inspect).join(', ')}"
|
15
|
+
end
|
16
|
+
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert_all_min_values!(*valid_values)
|
21
|
+
return assert_min_values!(*valid_values) unless empty?
|
22
|
+
|
23
|
+
raise ArgumentError, 'An empty array is not allowed'
|
24
|
+
end
|
25
|
+
|
6
26
|
def assert_valid_values!(*valid_values)
|
7
27
|
each do |value|
|
8
28
|
next if valid_values.include?(value)
|
9
29
|
|
10
30
|
raise ArgumentError,
|
11
|
-
"Invalid value: #{value.inspect}." \
|
31
|
+
"Invalid value: #{value.inspect}. " \
|
12
32
|
"Allowed values are: #{valid_values.map(&:inspect).join(', ')}"
|
13
33
|
end
|
14
34
|
end
|
data/lib/lite/ruby/hash.rb
CHANGED
@@ -16,11 +16,31 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
|
|
16
16
|
self
|
17
17
|
end
|
18
18
|
|
19
|
+
def assert_min_keys!(*valid_keys)
|
20
|
+
return self if empty?
|
21
|
+
|
22
|
+
valid_keys.each do |key|
|
23
|
+
next if key?(key)
|
24
|
+
|
25
|
+
raise ArgumentError,
|
26
|
+
"Missing key: #{key.inspect}. " \
|
27
|
+
"Minimum keys are: #{valid_keys.map(&:inspect).join(', ')}"
|
28
|
+
end
|
29
|
+
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def assert_all_min_keys!(*valid_keys)
|
34
|
+
return assert_min_keys!(*valid_keys) unless empty?
|
35
|
+
|
36
|
+
raise ArgumentError, 'An empty hash is not allowed'
|
37
|
+
end
|
38
|
+
|
19
39
|
def assert_pair_presence!(*valid_keys)
|
20
40
|
each do |key, value|
|
21
41
|
if !valid_keys.include?(key)
|
22
42
|
raise ArgumentError,
|
23
|
-
"Invalid key: #{key.inspect}." \
|
43
|
+
"Invalid key: #{key.inspect}. " \
|
24
44
|
"Allowed keys are: #{valid_keys.map(&:inspect).join(', ')}"
|
25
45
|
elsif value.respond_to?(:blank?) ? value.blank? : !value
|
26
46
|
raise ArgumentError, "A #{value.inspect} value for #{key.inspect} is not allowed"
|
@@ -39,7 +59,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
|
|
39
59
|
next if valid_keys.include?(key)
|
40
60
|
|
41
61
|
raise ArgumentError,
|
42
|
-
"Invalid key: #{key.inspect}." \
|
62
|
+
"Invalid key: #{key.inspect}. " \
|
43
63
|
"Allowed keys are: #{valid_keys.map(&:inspect).join(', ')}"
|
44
64
|
end
|
45
65
|
end
|
@@ -55,7 +75,7 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
|
|
55
75
|
next if valid_values.include?(value)
|
56
76
|
|
57
77
|
raise ArgumentError,
|
58
|
-
"Invalid value: #{value.inspect}." \
|
78
|
+
"Invalid value: #{value.inspect}. " \
|
59
79
|
"Allowed values are: #{valid_values.map(&:inspect).join(', ')}"
|
60
80
|
end
|
61
81
|
end
|
data/lib/lite/ruby/version.rb
CHANGED