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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef811fb97a57de64f738ad9e122101b8cb67f62f1e668a5581f7da8306f5cb99
4
- data.tar.gz: c346ae25ffe07110f22af1707cd43e2a6f66082fdf2aed8dca8ebc6f7b8c74f2
3
+ metadata.gz: b62cca1155994d26807711ee316fea8f1b34f3669decacd5345c77662ea1cbc8
4
+ data.tar.gz: 57d062e524a7a4b208a05748b06e86d5b9a5c9b68874ecb8135f86e3e8560aa4
5
5
  SHA512:
6
- metadata.gz: 66e57eeb88cd9c9410d995844c01d636336d25617b31c4281cc54d5b20e1602d53a76857e40ccbcafacf811a35ad0f8d60da719d2e4ed2be95a7764d7740e63b
7
- data.tar.gz: abb53b6a2ee6ceee251a8f404d21a803c2190819fe996101895fd4138184443152b6118087917e7bf3d6ad19f069341ccbd13543f70b81c96c5d17b883493f6b
6
+ metadata.gz: e11837df013186190c43feae3712be25a4bc286ac975b50219771ed055b0848501c5753759f81cc2e2ae288966a6b594b983b7d5f25101add2eeab57e6a4cf7f
7
+ data.tar.gz: e4ea9ea29831381e7e363fde4b4a98129e42a00284bcbbd4fc9ede53bb48b0c4118c99f337b00d69b6f9bde344ec48038d1896cc3f8ec09c53064cab29c5673b
@@ -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!`
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.18)
4
+ lite-ruby (1.0.19)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -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) #=> { foo: 'bar' }
10
- [:foo, :bar].assert_valid_values!(:foo, :boo) #=> raises ArgumentError: 'Invalid value: ":baz". Allowed values are: ":foo", ":boo"'
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! #=> { foo: 'bar' }
45
+ [:foo].assert_value_presence! #=> [:foo]
28
46
  [nil].assert_value_presence! #=> raises ArgumentError: 'A 'nil' value is not allowed'
29
47
  ```
30
48
 
@@ -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.
@@ -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
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.18'
6
+ VERSION ||= '1.0.19'
7
7
 
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.18
4
+ version: 1.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez