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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +2 -2
- data/docs/ARRAY.md +24 -6
- data/docs/HASH.md +27 -8
- data/docs/OBJECT.md +9 -0
- data/docs/TIME.md +4 -4
- data/lib/lite/ruby/array.rb +14 -0
- data/lib/lite/ruby/hash.rb +20 -1
- data/lib/lite/ruby/object.rb +4 -0
- data/lib/lite/ruby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef811fb97a57de64f738ad9e122101b8cb67f62f1e668a5581f7da8306f5cb99
|
4
|
+
data.tar.gz: c346ae25ffe07110f22af1707cd43e2a6f66082fdf2aed8dca8ebc6f7b8c74f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66e57eeb88cd9c9410d995844c01d636336d25617b31c4281cc54d5b20e1602d53a76857e40ccbcafacf811a35ad0f8d60da719d2e4ed2be95a7764d7740e63b
|
7
|
+
data.tar.gz: abb53b6a2ee6ceee251a8f404d21a803c2190819fe996101895fd4138184443152b6118087917e7bf3d6ad19f069341ccbd13543f70b81c96c5d17b883493f6b
|
data/CHANGELOG.md
CHANGED
@@ -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
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lite-ruby (1.0.
|
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.
|
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)
|
data/docs/ARRAY.md
CHANGED
@@ -2,20 +2,38 @@
|
|
2
2
|
|
3
3
|
`assert_valid_values!`
|
4
4
|
------
|
5
|
-
Raises an error if
|
5
|
+
Raises an error if value is not included in a list of values.
|
6
6
|
|
7
7
|
```ruby
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
15
|
+
Raises an error like `assert_valid_values!` but also on empty.
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
|
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`
|
data/docs/HASH.md
CHANGED
@@ -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
|
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
|
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'
|
data/docs/OBJECT.md
CHANGED
@@ -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`.
|
data/docs/TIME.md
CHANGED
@@ -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 |
|
data/lib/lite/ruby/array.rb
CHANGED
@@ -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
|
|
data/lib/lite/ruby/hash.rb
CHANGED
@@ -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]
|
446
|
+
value = self[key]
|
447
|
+
respond_to?(:blank?) ? value.blank? : !value
|
429
448
|
end
|
430
449
|
|
431
450
|
end
|
data/lib/lite/ruby/object.rb
CHANGED
data/lib/lite/ruby/version.rb
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.0.
|
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-
|
11
|
+
date: 2019-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|