monolens 0.5.1 → 0.5.2
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/README.md +2 -0
- data/lib/monolens/check/not_empty.rb +26 -0
- data/lib/monolens/check.rb +11 -0
- data/lib/monolens/coerce/date.rb +1 -1
- data/lib/monolens/coerce/date_time.rb +1 -1
- data/lib/monolens/version.rb +1 -1
- data/lib/monolens.rb +2 -1
- data/spec/monolens/check/test_not_empty.rb +50 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b96981f78af52f468676e9de0aeb3f79e79ab66
|
4
|
+
data.tar.gz: fb6445fc49c216be5868b27bef78cdfba79a1264
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 110e2c7da4dcc2195599813adf977af62d1698255339d0ba087bb1b1a7fb886ffd90bd12ded6eeb720547c327294eec758ae462f7e98024fffaecddb8e56c2cd
|
7
|
+
data.tar.gz: 1621c07cbba992d5a74c0811e420dd8489ff1c064eaf26bd698404b61bc3ab64ca60da65827ac3a061d0dfad28c483d3e2c07f83e50b4ec5eb22ea944b91d134
|
data/README.md
CHANGED
@@ -102,6 +102,8 @@ coerce.integer - Coerces the input value to an integer
|
|
102
102
|
array.compact - Removes null from the input array
|
103
103
|
array.join - Joins values of the input array as a string
|
104
104
|
array.map - Apply a lens to each member of an Array
|
105
|
+
|
106
|
+
check.notEmpty - Throws an error if the input is null or empty
|
105
107
|
```
|
106
108
|
|
107
109
|
## Public API
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
module Monolens
|
4
|
+
module Check
|
5
|
+
class NotEmpty
|
6
|
+
include Lens
|
7
|
+
|
8
|
+
def call(arg, world = {})
|
9
|
+
if arg.nil?
|
10
|
+
do_fail!(arg, world)
|
11
|
+
elsif arg.respond_to?(:empty?) && arg.empty?
|
12
|
+
do_fail!(arg, world)
|
13
|
+
else
|
14
|
+
arg
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def do_fail!(arg, world)
|
21
|
+
message = option(:message, 'Input may not be empty')
|
22
|
+
fail!(message, world)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/monolens/coerce/date.rb
CHANGED
data/lib/monolens/version.rb
CHANGED
data/lib/monolens.rb
CHANGED
@@ -19,6 +19,7 @@ module Monolens
|
|
19
19
|
require_relative 'monolens/array'
|
20
20
|
require_relative 'monolens/object'
|
21
21
|
require_relative 'monolens/coerce'
|
22
|
+
require_relative 'monolens/check'
|
22
23
|
|
23
24
|
def load_file(file)
|
24
25
|
Monolens::File.new(YAML.safe_load(::File.read(file)))
|
@@ -59,7 +60,7 @@ module Monolens
|
|
59
60
|
raise "Invalid lens #{arg}" unless arg.size == 1
|
60
61
|
|
61
62
|
name, options = arg.to_a.first
|
62
|
-
namespace_name, lens_name = if name =~ /^[a-z]+\.[a-z]+$/
|
63
|
+
namespace_name, lens_name = if name =~ /^[a-z]+\.[a-z][a-zA-Z]+$/
|
63
64
|
name.to_s.split('.')
|
64
65
|
else
|
65
66
|
['core', name]
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Monolens, 'check.notEmpty' do
|
4
|
+
subject do
|
5
|
+
Monolens.lens('check.notEmpty' => options)
|
6
|
+
end
|
7
|
+
|
8
|
+
context 'with default options' do
|
9
|
+
let(:options) do
|
10
|
+
{}
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'works on non empty strings' do
|
14
|
+
input = '12'
|
15
|
+
expect(subject.call(input)).to be(input)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'works on non empty arrays' do
|
19
|
+
input = ['12']
|
20
|
+
expect(subject.call(input)).to be(input)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'raises on empty strings' do
|
24
|
+
input = ''
|
25
|
+
expect {
|
26
|
+
subject.call(input)
|
27
|
+
}.to raise_error(Monolens::LensError, 'Input may not be empty')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'raises on empty arrays' do
|
31
|
+
input = []
|
32
|
+
expect {
|
33
|
+
subject.call(input)
|
34
|
+
}.to raise_error(Monolens::LensError, 'Input may not be empty')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'with a specific error message' do
|
39
|
+
let(:options) do
|
40
|
+
{ message: 'Hello failure!' }
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'raises on empty strings' do
|
44
|
+
input = ''
|
45
|
+
expect {
|
46
|
+
subject.call(input)
|
47
|
+
}.to raise_error(Monolens::LensError, 'Hello failure!')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monolens
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -82,6 +82,8 @@ files:
|
|
82
82
|
- lib/monolens/array/compact.rb
|
83
83
|
- lib/monolens/array/join.rb
|
84
84
|
- lib/monolens/array/map.rb
|
85
|
+
- lib/monolens/check.rb
|
86
|
+
- lib/monolens/check/not_empty.rb
|
85
87
|
- lib/monolens/coerce.rb
|
86
88
|
- lib/monolens/coerce/date.rb
|
87
89
|
- lib/monolens/coerce/date_time.rb
|
@@ -120,6 +122,7 @@ files:
|
|
120
122
|
- spec/monolens/array/test_compact.rb
|
121
123
|
- spec/monolens/array/test_join.rb
|
122
124
|
- spec/monolens/array/test_map.rb
|
125
|
+
- spec/monolens/check/test_not_empty.rb
|
123
126
|
- spec/monolens/coerce/test_date.rb
|
124
127
|
- spec/monolens/coerce/test_datetime.rb
|
125
128
|
- spec/monolens/coerce/test_integer.rb
|