atacama 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +7 -1
- data/Rakefile +4 -0
- data/atacama.gemspec +1 -0
- data/lib/atacama.rb +22 -0
- data/lib/atacama/contract.rb +3 -1
- data/lib/atacama/contract/validator.rb +5 -2
- data/lib/atacama/transaction.rb +3 -1
- data/lib/atacama/types.rb +8 -3
- data/lib/atacama/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4167c02e2fbe257dc68db7fab4de63e5f6d12c10
|
4
|
+
data.tar.gz: 719fd17923503f7f0cb4aaac835156f5a1efe481
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a54f18d7cf601e141ba8f3cb5a62c2bed2415dd875dc75a00ac509ef398da7e13ba90813f58ed502d16e7974907dff0f6d0cdffb69e93956af7d592b7e079b0c
|
7
|
+
data.tar.gz: 4e9a3108aff20d51ca6d8dd847b7f06564012c8f48a5411a91170c987f164397292b80e1ea045a1c9395929cc7db49c9803b12c947bb211ec858f99433278c2f
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
atacama (0.1.
|
4
|
+
atacama (0.1.10)
|
5
5
|
dry-types (~> 0.13.2)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
coderay (1.1.2)
|
10
11
|
concurrent-ruby (1.0.5)
|
11
12
|
dry-configurable (0.7.0)
|
12
13
|
concurrent-ruby (~> 1.0)
|
@@ -28,7 +29,11 @@ GEM
|
|
28
29
|
dry-equalizer (~> 0.2)
|
29
30
|
dry-inflector (~> 0.1, >= 0.1.2)
|
30
31
|
dry-logic (~> 0.4, >= 0.4.2)
|
32
|
+
method_source (0.9.2)
|
31
33
|
minitest (5.11.3)
|
34
|
+
pry (0.12.2)
|
35
|
+
coderay (~> 1.1.0)
|
36
|
+
method_source (~> 0.9.0)
|
32
37
|
rake (10.5.0)
|
33
38
|
|
34
39
|
PLATFORMS
|
@@ -38,6 +43,7 @@ DEPENDENCIES
|
|
38
43
|
atacama!
|
39
44
|
bundler (~> 1.16)
|
40
45
|
minitest (~> 5.0)
|
46
|
+
pry
|
41
47
|
rake (~> 10.0)
|
42
48
|
|
43
49
|
BUNDLED WITH
|
data/Rakefile
CHANGED
@@ -12,3 +12,7 @@ task default: :test
|
|
12
12
|
task :watch do
|
13
13
|
exec 'docker run -v `pwd`:/app:cached -it spatialnetworks/alpine bash -l -c "gem install rerun && bundle && /usr/local/bundle/bin/rerun -x rake"'
|
14
14
|
end
|
15
|
+
|
16
|
+
task :debug do
|
17
|
+
exec 'docker run -v `pwd`:/app:cached -it spatialnetworks/alpine bash -l -c "bundle && rake"'
|
18
|
+
end
|
data/atacama.gemspec
CHANGED
data/lib/atacama.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dry-types'
|
2
4
|
require 'atacama/version'
|
3
5
|
require 'atacama/contract'
|
@@ -21,4 +23,24 @@ module Atacama
|
|
21
23
|
rescue Dry::Types::ConstraintError => exception
|
22
24
|
yield exception
|
23
25
|
end
|
26
|
+
|
27
|
+
# Generate more human readable error messages for type errors.
|
28
|
+
#
|
29
|
+
# @param klass [Class] the class dispatching the exception
|
30
|
+
# @param exception [Dry::Types::]
|
31
|
+
def self.format_exception(klass, exception, description)
|
32
|
+
[
|
33
|
+
'',
|
34
|
+
'',
|
35
|
+
'Source:',
|
36
|
+
" #{klass}",
|
37
|
+
'',
|
38
|
+
'Description:',
|
39
|
+
" #{description}",
|
40
|
+
'',
|
41
|
+
'Error:',
|
42
|
+
" The value #{exception.input.inspect} failed the following test: #{exception.result}",
|
43
|
+
''
|
44
|
+
].join("\n")
|
45
|
+
end
|
24
46
|
end
|
data/lib/atacama/contract.rb
CHANGED
@@ -91,7 +91,9 @@ module Atacama
|
|
91
91
|
# @param value [Any] the object to type check
|
92
92
|
def validate_return(value)
|
93
93
|
Atacama.check(return_type, value) do |e|
|
94
|
-
raise ReturnTypeMismatchError,
|
94
|
+
raise ReturnTypeMismatchError, Atacama.format_exception(self, e,
|
95
|
+
'The return value was an incorrect type.',
|
96
|
+
)
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
@@ -25,8 +25,11 @@ module Atacama
|
|
25
25
|
|
26
26
|
def detect_invalid_types!
|
27
27
|
options.each do |key, parameter|
|
28
|
-
|
29
|
-
|
28
|
+
value = context[key]
|
29
|
+
Atacama.check parameter.type, value do |e|
|
30
|
+
raise OptionTypeMismatchError, Atacama.format_exception(klass, e,
|
31
|
+
"The value #{value.inspect} for #{key.inspect} is the incorrect type"
|
32
|
+
)
|
30
33
|
end
|
31
34
|
end
|
32
35
|
end
|
data/lib/atacama/transaction.rb
CHANGED
@@ -35,7 +35,9 @@ module Atacama
|
|
35
35
|
returns(
|
36
36
|
Types.Instance(Result).constructor do |options|
|
37
37
|
Atacama.check(type, options.value) do |e|
|
38
|
-
raise ResultTypeMismatchError,
|
38
|
+
raise ResultTypeMismatchError, Atacama.format_exception(self, e,
|
39
|
+
"Option(#{key.inspect}) returned from the Transaction was the incorrect type.",
|
40
|
+
)
|
39
41
|
end
|
40
42
|
|
41
43
|
options
|
data/lib/atacama/types.rb
CHANGED
@@ -16,8 +16,11 @@ module Atacama
|
|
16
16
|
Instance(Values::Option).constructor do |value_object|
|
17
17
|
if value_object.is_a? Values::Option
|
18
18
|
map.each do |key, type|
|
19
|
-
|
20
|
-
|
19
|
+
value = value_object.value[key]
|
20
|
+
Atacama.check(type, value) do |e|
|
21
|
+
raise OptionTypeMismatchError, Atacama.format_exception(self, e,
|
22
|
+
"The Option() #{key.inspect} value #{value.inspect} is the incorrect type."
|
23
|
+
)
|
21
24
|
end
|
22
25
|
end
|
23
26
|
end
|
@@ -36,7 +39,9 @@ module Atacama
|
|
36
39
|
Instance(Values::Return).constructor do |value_object|
|
37
40
|
if value_object.is_a?(Values::Return)
|
38
41
|
Atacama.check(type, value_object.value) do |e|
|
39
|
-
raise ReturnTypeMismatchError,
|
42
|
+
raise ReturnTypeMismatchError, Atacama.format_exception(self, e,
|
43
|
+
"The Return() value #{value_object.value.inspect} does not match the declared type."
|
44
|
+
)
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
data/lib/atacama/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: atacama
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tyler Johnston
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Service objects using composable contracts
|
70
84
|
email:
|
71
85
|
- tyler@spatialnetworks.com
|