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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bad140ab2ab9b93fcd0d3d67ae9765cac0a6ef2e
4
- data.tar.gz: 5ba6c31aedd1f8175bece9df427ab9f57eeee6f5
3
+ metadata.gz: 4167c02e2fbe257dc68db7fab4de63e5f6d12c10
4
+ data.tar.gz: 719fd17923503f7f0cb4aaac835156f5a1efe481
5
5
  SHA512:
6
- metadata.gz: aa1c928c33fa5dd1bd466c45f2c9d7c2b5bdff68012647dbdab19222864c94b78df88cde3700726bd6fa9e2a93b27b1009621486aa39f77d57ee1cb53fe0520d
7
- data.tar.gz: 56e6c4edc97a07ef00c685620ef9c54437200ec66716c5d12eba193769b48fc5486fad8e194c39459ea7364427414f58eeb7a0f9be51d46a66de0353971a8772
6
+ metadata.gz: a54f18d7cf601e141ba8f3cb5a62c2bed2415dd875dc75a00ac509ef398da7e13ba90813f58ed502d16e7974907dff0f6d0cdffb69e93956af7d592b7e079b0c
7
+ data.tar.gz: 4e9a3108aff20d51ca6d8dd847b7f06564012c8f48a5411a91170c987f164397292b80e1ea045a1c9395929cc7db49c9803b12c947bb211ec858f99433278c2f
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atacama (0.1.9)
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
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'bundler', '~> 1.16'
29
29
  spec.add_development_dependency 'minitest', '~> 5.0'
30
30
  spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'pry'
31
32
  end
@@ -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
@@ -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, "#{self} return value invalid: #{e.message}"
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
- Atacama.check parameter.type, context[key] do |e|
29
- raise OptionTypeMismatchError, %(#{klass} option :#{key} invalid: #{e.message})
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
@@ -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, "Invalid Result value for #{self}: #{e.message}"
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
@@ -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
- Atacama.check(type, value_object.value[key]) do |e|
20
- raise OptionTypeMismatchError, "#{self} Invalid Option value type: #{e.message}"
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, "#{self} Invalid Return Value type: #{e.message}"
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
 
@@ -1,3 +1,3 @@
1
1
  module Atacama
2
- VERSION = '0.1.9'.freeze
2
+ VERSION = '0.1.10'.freeze
3
3
  end
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.9
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