lite-ruby 1.0.17 → 1.0.18

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: 1b4c2a37c0cc55a587d6c321baf3b4d6c26d89d51814cc8a995cca77c3061693
4
- data.tar.gz: fbd039fae33008ab9677d84f45f81a1e1cd590f64cb7f3f634454497c4674cf7
3
+ metadata.gz: ef811fb97a57de64f738ad9e122101b8cb67f62f1e668a5581f7da8306f5cb99
4
+ data.tar.gz: c346ae25ffe07110f22af1707cd43e2a6f66082fdf2aed8dca8ebc6f7b8c74f2
5
5
  SHA512:
6
- metadata.gz: 076e6cd76f6f24d874841c893714b949be8a0bf3af80494fb502c65ee53ea3167c028ce4edc209973b8c53c7b0b67d322934450814c5e30edc479edb0dcc64c0
7
- data.tar.gz: b39115a037aa26c299c382f2f1f1e1800bb059a9a36200150fb7ab77b4d414acceac8b59718933245471297d6391e43e1ebc7a6c4772e21691103079195e991b
6
+ metadata.gz: 66e57eeb88cd9c9410d995844c01d636336d25617b31c4281cc54d5b20e1602d53a76857e40ccbcafacf811a35ad0f8d60da719d2e4ed2be95a7764d7740e63b
7
+ data.tar.gz: abb53b6a2ee6ceee251a8f404d21a803c2190819fe996101895fd4138184443152b6118087917e7bf3d6ad19f069341ccbd13543f70b81c96c5d17b883493f6b
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.0.18] - 2019-09-03
10
+ ### Added
11
+ - Added Array => `assert_valid_values!`
12
+ - Added Array => `assert_all_valid_values!`
13
+ - Added Hash => `assert_pair_presence!`
14
+ - Added Hash => `assert_all_pair_presence!`
15
+ - Added Object => `presence`
16
+
9
17
  ## [1.0.17] - 2019-08-24
10
18
  ### Changed
11
19
  - Improved how configuration works
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-ruby (1.0.17)
4
+ lite-ruby (1.0.18)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -50,7 +50,7 @@ GEM
50
50
  nokogiri (1.10.4)
51
51
  mini_portile2 (~> 2.4.0)
52
52
  parallel (1.17.0)
53
- parser (2.6.3.0)
53
+ parser (2.6.4.0)
54
54
  ast (~> 2.4.0)
55
55
  rack (2.0.7)
56
56
  rack-test (1.1.0)
@@ -2,20 +2,38 @@
2
2
 
3
3
  `assert_valid_values!`
4
4
  ------
5
- Raises an error if key is not included in a list of values.
5
+ Raises an error if value is not included in a list of values.
6
6
 
7
7
  ```ruby
8
- {}.assert_valid_values!(:foo) #=> {}
9
- { foo: 'bar' }.assert_valid_values!(:foo) #=> { foo: 'bar' }
10
- { baz: 'boz' }.assert_valid_values!(:foo, :boo) #=> raises ArgumentError: 'Invalid value: ":baz". Allowed values are: ":foo", ":boo"'
8
+ [].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"'
11
11
  ```
12
12
 
13
13
  `assert_all_valid_values!`
14
14
  ------
15
- Raises like an error like `assert_valid_values!` but also on empty.
15
+ Raises an error like `assert_valid_values!` but also on empty.
16
16
 
17
17
  ```ruby
18
- {}.assert_all_valid_values!(:foo) #=> raises ArgumentError: 'An empty array is not allowed'
18
+ [].assert_all_valid_values!(:foo) #=> raises ArgumentError: 'An empty array is not allowed'
19
+ ```
20
+
21
+ `assert_value_presence!`
22
+ ------
23
+ Raises an error if value is not `present?` or is nil.
24
+
25
+ ```ruby
26
+ [].assert_value_presence! #=> []
27
+ [:foo].assert_value_presence! #=> { foo: 'bar' }
28
+ [nil].assert_value_presence! #=> raises ArgumentError: 'A 'nil' value is not allowed'
29
+ ```
30
+
31
+ `assert_all_value_presence!`
32
+ ------
33
+ Raises an error like `assert_value_presence!` but also on empty.
34
+
35
+ ```ruby
36
+ [].assert_all_value_presence! #=> raises ArgumentError: 'An empty array is not allowed'
19
37
  ```
20
38
 
21
39
  `after`
@@ -19,19 +19,38 @@ h1.aka('boo', :foo)
19
19
  h1['boo'] #=> 'bar'
20
20
  ```
21
21
 
22
+ `assert_pair_presence!`
23
+ ------
24
+ Raises an error if key is not included in a list of keys or if value is `blank?` or nil.
25
+
26
+ ```ruby
27
+ {}.assert_pair_presence!(:foo) #=> {}
28
+ { foo: 'bar' }.assert_pair_presence!(:foo) #=> { foo: 'bar' }
29
+ { foo: nil }.assert_pair_presence!(:foo) #=> raises ArgumentError: 'A "nil" value for ":foo" is not allowed'
30
+ { baz: 'boz' }.assert_pair_presence!(:foo, :boo) #=> raises ArgumentError: 'Invalid key: ":baz". Allowed keys are: ":foo", ":boo"'
31
+ ```
32
+
33
+ `assert_all_pair_presence!`
34
+ ------
35
+ Raises an error like `assert_pair_presence!` but also on empty.
36
+
37
+ ```ruby
38
+ {}.assert_all_pair_presence!(:foo) #=> raises ArgumentError: 'An empty hash is not allowed'
39
+ ```
40
+
22
41
  `assert_valid_keys!`
23
42
  ------
24
43
  Raises an error if key is not included in a list of keys.
25
44
 
26
45
  ```ruby
27
- {}.assert_valid_keys(:foo) #=> {}
28
- { foo: 'bar' }.assert_valid_keys(:foo) #=> { foo: 'bar' }
29
- { baz: 'boz' }.assert_valid_keys(:foo, :boo) #=> raises ArgumentError: 'Invalid key: ":baz". Allowed keys are: ":foo", ":boo"'
46
+ {}.assert_valid_keys!(:foo) #=> {}
47
+ { foo: 'bar' }.assert_valid_keys!(:foo) #=> { foo: 'bar' }
48
+ { baz: 'boz' }.assert_valid_keys!(:foo, :boo) #=> raises ArgumentError: 'Invalid key: ":baz". Allowed keys are: ":foo", ":boo"'
30
49
  ```
31
50
 
32
51
  `assert_all_valid_keys!`
33
52
  ------
34
- Raises like an error like `assert_valid_values!` but also on empty.
53
+ Raises an error like `assert_valid_values!` but also on empty.
35
54
 
36
55
  ```ruby
37
56
  {}.assert_all_valid_keys!(:foo) #=> raises ArgumentError: 'An empty hash is not allowed'
@@ -42,14 +61,14 @@ Raises like an error like `assert_valid_values!` but also on empty.
42
61
  Raises an error if value is not included in a list of values.
43
62
 
44
63
  ```ruby
45
- {}.assert_valid_values(:foo) #=> {}
46
- { foo: 'bar' }.assert_valid_values('bar') #=> { foo: 'bar' }
47
- { baz: 'boz' }.assert_valid_values(:foo, :boo) #=> raises ArgumentError: 'Invalid value: "boz". Allowed values are: ":foo", ":boo"'
64
+ {}.assert_valid_values!(:foo) #=> {}
65
+ { foo: 'bar' }.assert_valid_values!('bar') #=> { foo: 'bar' }
66
+ { baz: 'boz' }.assert_valid_values!(:foo, :boo) #=> raises ArgumentError: 'Invalid value: "boz". Allowed values are: ":foo", ":boo"'
48
67
  ```
49
68
 
50
69
  `assert_all_valid_values!`
51
70
  ------
52
- Raises like an error like `assert_valid_values!` but also on empty.
71
+ Raises an error like `assert_valid_values!` but also on empty.
53
72
 
54
73
  ```ruby
55
74
  {}.assert_all_valid_values!(:foo) #=> raises ArgumentError: 'An empty hash is not allowed'
@@ -151,6 +151,15 @@ Returns if an object is not empty or `nil`.
151
151
  ''.present? #=> false
152
152
  ```
153
153
 
154
+ `presence`
155
+ ------
156
+ Returns object if it's `present?`.
157
+
158
+ ```ruby
159
+ 'bar'.presence || 'foo' #=> 'bar'
160
+ nil.presence || 'foo' #=> 'foo'
161
+ ```
162
+
154
163
  `range?`
155
164
  ------
156
165
  Returns if an object is a `range`.
@@ -67,10 +67,10 @@ Converts a `time` object to a predefined format.
67
67
  | Combo | 24h time | `:time_blank` | %k:%M %z | 0:31 |
68
68
  | Combo | 24h time | `:time_tz` | %H:%M %z | 00:31 +0000 |
69
69
  | Combo | 24h time | `:time_tzn` | %H:%M %Z | 00:31 UTC |
70
- | Combo | 12h time | `:time_12`, `:time_12_padded` | %I:%M %P | 07:31 |
71
- | Combo | 12h time | `:time_12_blank` | %l:%M %P | 7:31 |
72
- | Combo | 12h Time | `:time_12_tz` | %I:%M %z | 07:31 am +0000 |
73
- | Combo | 12h Time | `:time_12_tzn` | %I:%M %Z | 07:31 am UTC |
70
+ | Combo | 12h time | `:time_12`, `:time_12_padded` | %I:%M %P | 07:31 am |
71
+ | Combo | 12h time | `:time_12_blank` | %l:%M %P | 7:31 am |
72
+ | Combo | 12h Time | `:time_12_tz` | %I:%M %P %z | 07:31 am +0000 |
73
+ | Combo | 12h Time | `:time_12_tzn` | %I:%M %P %Z | 07:31 am UTC |
74
74
  | Combo | 24h daytime | `:daytime` | %B %-d %H:%M | January 9 00:31 |
75
75
  | Combo | 24h daytime | `:daytime_abbr` | %b %-d %H:%M | Jan 9 00:31 |
76
76
  | Combo | 24h daytime | `:daytime_iso` | %m-%d %H:%M | 01-09 00:31 |
@@ -19,6 +19,20 @@ if Lite::Ruby.configuration.monkey_patches.include?('array')
19
19
  raise ArgumentError, 'An empty array is not allowed'
20
20
  end
21
21
 
22
+ def assert_value_presence!
23
+ each do |value|
24
+ next if value.respond_to?(:present?) ? value.present? : value
25
+
26
+ raise ArgumentError, "A #{value.inspect} value is not allowed"
27
+ end
28
+ end
29
+
30
+ def assert_all_value_presence!
31
+ return assert_value_presence! unless empty?
32
+
33
+ raise ArgumentError, 'An empty array is not allowed'
34
+ end
35
+
22
36
  def after(value)
23
37
  return unless include?(value)
24
38
 
@@ -16,6 +16,24 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
16
16
  self
17
17
  end
18
18
 
19
+ def assert_pair_presence!(*valid_keys)
20
+ each do |key, value|
21
+ if !valid_keys.include?(key)
22
+ raise ArgumentError,
23
+ "Invalid key: #{key.inspect}." \
24
+ "Allowed keys are: #{valid_keys.map(&:inspect).join(', ')}"
25
+ elsif value.respond_to?(:blank?) ? value.blank? : !value
26
+ raise ArgumentError, "A #{value.inspect} value for #{key.inspect} is not allowed"
27
+ end
28
+ end
29
+ end
30
+
31
+ def assert_all_pair_presence!(*valid_keys)
32
+ return assert_pair_presence!(*valid_keys) unless empty?
33
+
34
+ raise ArgumentError, 'An empty hash is not allowed'
35
+ end
36
+
19
37
  def assert_valid_keys!(*valid_keys)
20
38
  each_key do |key|
21
39
  next if valid_keys.include?(key)
@@ -425,7 +443,8 @@ if Lite::Ruby.configuration.monkey_patches.include?('hash')
425
443
  end
426
444
 
427
445
  def vacant?(key)
428
- self[key].blank?
446
+ value = self[key]
447
+ respond_to?(:blank?) ? value.blank? : !value
429
448
  end
430
449
 
431
450
  end
@@ -91,6 +91,10 @@ if Lite::Ruby.configuration.monkey_patches.include?('object')
91
91
  !blank?
92
92
  end
93
93
 
94
+ def presence
95
+ self if present?
96
+ end
97
+
94
98
  def range?
95
99
  is_a?(Range)
96
100
  end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Ruby
5
5
 
6
- VERSION ||= '1.0.17'
6
+ VERSION ||= '1.0.18'
7
7
 
8
8
  end
9
9
  end
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.0.17
4
+ version: 1.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-24 00:00:00.000000000 Z
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler