interactor-contracts 0.1.0 → 0.2.0
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 +5 -5
- data/CHANGELOG.md +15 -1
- data/README.md +2 -3
- data/interactor-contracts.gemspec +16 -16
- data/lib/interactor-contracts.rb +3 -2
- data/lib/interactor/contracts.rb +10 -10
- data/lib/interactor/contracts/breach.rb +3 -1
- data/lib/interactor/contracts/breach_set.rb +11 -4
- data/lib/interactor/contracts/contract.rb +4 -1
- data/lib/interactor/contracts/dsl.rb +26 -3
- data/lib/interactor/contracts/errors.rb +2 -0
- data/lib/interactor/contracts/outcome.rb +6 -4
- data/lib/interactor/contracts/terms.rb +5 -3
- data/lib/interactor/contracts/version.rb +3 -1
- metadata +5 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 155341334dd614cae42bd73f08e6791280ba8481ce82fb99c1803ec6efff45b4
|
4
|
+
data.tar.gz: e57c5cd09039e621a0df9bec33b6fcfc98b543b5d99eaf0caebc2aeb1069abdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67e22c927d40745bb42ffa6746e3f4685282c632e05f6fb18f266a686f5c10f2c339ddba5e98604d4718ce5bc47254654054775acc0d5af78ed55ef86e2e566b
|
7
|
+
data.tar.gz: 199b4e95400eadea32fcba1cec5517d859a06fc57ebd394ebbd5a2497d2f90d56cde7fa6878ce261d7d792bea9b7262c89ede01e21fdba501a02109ae6b2f0e1
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file. This projec
|
|
4
4
|
|
5
5
|
[semver]: http://semver.org/spec/v2.0.0.html
|
6
6
|
|
7
|
+
## [0.2.0] - 2019-05-27
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
* [#18](https://github.com/michaelherold/interactor-contracts/pull/18): Add possibility to inherit class with saving interactor-contracts behaviour - [@raykov](https://github.com/raykov).
|
12
|
+
|
13
|
+
### Fixed
|
14
|
+
|
15
|
+
* [#16](https://github.com/michaelherold/interactor-contracts/pull/16): Fix BreachSet#to_hash issue with hashed messages in Breaches - [@raykov](https://github.com/raykov).
|
16
|
+
|
17
|
+
### Security
|
18
|
+
|
19
|
+
* [#15](https://github.com/michaelherold/interactor-contracts/pull/15): Update vulnerable dependencies in the development harness. No user-facing change - [@michaelherold](https://github.com/michaelherold).
|
20
|
+
|
7
21
|
## [0.1.0] - 2017-02-25
|
8
22
|
|
9
23
|
### Added
|
@@ -21,5 +35,5 @@ All notable changes to this project will be documented in this file. This projec
|
|
21
35
|
* [#4](https://github.com/michaelherold/interactor-contracts/pull/4): Added Danger as a collaboration tool - [@michaelherold](https://github.com/michaelherold).
|
22
36
|
* [#6](https://github.com/michaelherold/interactor-contracts/pull/6): Updated the README - [@michaelherold](https://github.com/michaelherold).
|
23
37
|
|
24
|
-
|
38
|
+
[0.2.0]: https://github.com/michaelherold/interactor-contracts/compare/v0.1.0...v0.2.0
|
25
39
|
[0.1.0]: https://github.com/michaelherold/interactor-contracts/tree/v0.1.0
|
data/README.md
CHANGED
@@ -137,10 +137,9 @@ https://github.com/michaelherold/interactor-contracts.
|
|
137
137
|
This library aims to support and is [tested against][travis] the following Ruby
|
138
138
|
versions:
|
139
139
|
|
140
|
-
* Ruby 2.1
|
141
|
-
* Ruby 2.2
|
142
|
-
* Ruby 2.3
|
143
140
|
* Ruby 2.4
|
141
|
+
* Ruby 2.5
|
142
|
+
* Ruby 2.6
|
144
143
|
* JRuby 9.1
|
145
144
|
|
146
145
|
If something doesn't work on one of these versions, it's a bug.
|
@@ -1,25 +1,25 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require File.expand_path(
|
3
|
+
require File.expand_path('../lib/interactor/contracts/version', __FILE__)
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
6
|
+
spec.name = 'interactor-contracts'
|
7
7
|
spec.version = Interactor::Contracts::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
8
|
+
spec.authors = ['Michael Herold']
|
9
|
+
spec.email = ['michael.j.herold@gmail.com']
|
10
10
|
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
11
|
+
spec.summary = 'Add contacts to your interactors'
|
12
|
+
spec.description = 'Add contacts to your interactors'
|
13
|
+
spec.homepage = 'https://github.com/michaelherold/interactor-contracts'
|
14
|
+
spec.license = 'MIT'
|
15
15
|
|
16
|
-
spec.files = %w
|
17
|
-
spec.files += %w
|
18
|
-
spec.files += Dir[
|
19
|
-
spec.require_paths = [
|
16
|
+
spec.files = %w[CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md]
|
17
|
+
spec.files += %w[interactor-contracts.gemspec]
|
18
|
+
spec.files += Dir['lib/**/*.rb']
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
21
|
+
spec.add_dependency 'dry-validation', '~> 0.10'
|
22
|
+
spec.add_dependency 'interactor', '~> 3'
|
23
23
|
|
24
|
-
spec.add_development_dependency
|
24
|
+
spec.add_development_dependency 'bundler', '> 1.11'
|
25
25
|
end
|
data/lib/interactor-contracts.rb
CHANGED
@@ -1,2 +1,3 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'interactor/contracts'
|
data/lib/interactor/contracts.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-validation'
|
4
|
+
require 'interactor'
|
5
|
+
require 'interactor/contracts/dsl'
|
6
|
+
require 'interactor/contracts/errors'
|
5
7
|
|
6
8
|
module Interactor
|
7
9
|
# Create a contract for your interactor that specifies what it expects as
|
@@ -14,7 +16,7 @@ module Interactor
|
|
14
16
|
# @return [void]
|
15
17
|
def self.included(descendant)
|
16
18
|
unless descendant.include?(Interactor)
|
17
|
-
|
19
|
+
raise NotAnInteractor, "#{descendant} does not include `Interactor'"
|
18
20
|
end
|
19
21
|
descendant.extend(DSL)
|
20
22
|
end
|
@@ -35,12 +37,10 @@ module Interactor
|
|
35
37
|
# @param [#call] contracts a callable object
|
36
38
|
# @return [void]
|
37
39
|
def enforce_contracts(contracts)
|
38
|
-
outcome = contracts.call(context)
|
40
|
+
return unless (outcome = contracts.call(context)).failure?
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
-
instance_exec(outcome.breaches, &handler)
|
43
|
-
end
|
42
|
+
contract.consequences.each do |handler|
|
43
|
+
instance_exec(outcome.breaches, &handler)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Interactor
|
2
4
|
module Contracts
|
3
5
|
# A wrapper for breached contract terms that encapsulates the failed
|
@@ -53,7 +55,7 @@ module Interactor
|
|
53
55
|
# @api public
|
54
56
|
# @return [Hash]
|
55
57
|
def to_h
|
56
|
-
{property => messages}
|
58
|
+
{ property => messages }
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'delegate'
|
2
4
|
|
3
5
|
module Interactor
|
4
6
|
module Contracts
|
@@ -35,12 +37,17 @@ module Interactor
|
|
35
37
|
# @api public
|
36
38
|
# @return [Hash] a hash with property keys and message values
|
37
39
|
def to_hash
|
38
|
-
|
39
|
-
result[property] =
|
40
|
+
each_with_object({}) do |(property, messages), result|
|
41
|
+
result[property] =
|
42
|
+
if messages.is_a?(Hash)
|
43
|
+
Hash(result[property]).merge(messages)
|
44
|
+
else
|
45
|
+
Array(result[property]) | messages
|
46
|
+
end
|
40
47
|
result
|
41
48
|
end
|
42
49
|
end
|
43
|
-
|
50
|
+
alias to_h to_hash
|
44
51
|
end
|
45
52
|
end
|
46
53
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'interactor/contracts/terms'
|
2
4
|
|
3
5
|
module Interactor
|
4
6
|
module Contracts
|
@@ -20,6 +22,7 @@ module Interactor
|
|
20
22
|
@consequences = consequences
|
21
23
|
@expectations = expectations
|
22
24
|
end
|
25
|
+
# rubocop:enable Metrics/LineLength
|
23
26
|
|
24
27
|
# The assurances the Contract will fulfill
|
25
28
|
#
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'interactor/contracts/contract'
|
2
4
|
|
3
5
|
module Interactor
|
4
6
|
module Contracts
|
@@ -75,6 +77,18 @@ module Interactor
|
|
75
77
|
define_expectations_hook
|
76
78
|
end
|
77
79
|
|
80
|
+
# Sets contract to given one and calls hooks
|
81
|
+
# define_assurances_hook and define_expectations_hook
|
82
|
+
#
|
83
|
+
# @api semipublic
|
84
|
+
# @param [Contract] contract
|
85
|
+
# @return [void]
|
86
|
+
def inherit_contract(contract)
|
87
|
+
@contract = contract
|
88
|
+
define_assurances_hook
|
89
|
+
define_expectations_hook
|
90
|
+
end
|
91
|
+
|
78
92
|
# Defines a consequence that is called when a contract is breached
|
79
93
|
#
|
80
94
|
# @example
|
@@ -111,14 +125,14 @@ module Interactor
|
|
111
125
|
# @api private
|
112
126
|
# @return [TrueClass, FalseClass] true if the hook is defined
|
113
127
|
attr_reader :defined_assurances_hook
|
114
|
-
|
128
|
+
alias defined_assurances_hook? defined_assurances_hook
|
115
129
|
|
116
130
|
# Flags whether the expectations hook has been defined
|
117
131
|
#
|
118
132
|
# @api private
|
119
133
|
# @return [TrueClass, FalseClass] true if the hook is defined
|
120
134
|
attr_reader :defined_expectations_hook
|
121
|
-
|
135
|
+
alias defined_expectations_hook? defined_expectations_hook
|
122
136
|
|
123
137
|
# Defines an after hook that validates the Interactor's output
|
124
138
|
#
|
@@ -145,6 +159,15 @@ module Interactor
|
|
145
159
|
|
146
160
|
@defined_expectations_hook = true
|
147
161
|
end
|
162
|
+
|
163
|
+
# Defines a callback for class inheritance
|
164
|
+
#
|
165
|
+
# @api private
|
166
|
+
# @param [Class] child a child of inherited class
|
167
|
+
# @return [void]
|
168
|
+
def inherited(child)
|
169
|
+
child.inherit_contract(contract)
|
170
|
+
end
|
148
171
|
end
|
149
172
|
end
|
150
173
|
end
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
require 'interactor/contracts/breach'
|
5
|
+
require 'interactor/contracts/breach_set'
|
4
6
|
|
5
7
|
module Interactor
|
6
8
|
module Contracts
|
@@ -46,7 +48,7 @@ module Interactor
|
|
46
48
|
# @api semipublic
|
47
49
|
# @return [Array<Breach>] the breaches of the Terms' constraints
|
48
50
|
def breaches
|
49
|
-
BreachSet.new(result.messages(:
|
51
|
+
BreachSet.new(result.messages(full: true).map do |property, messages|
|
50
52
|
Breach.new(property, messages)
|
51
53
|
end)
|
52
54
|
end
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dry-validation'
|
4
|
+
require 'interactor/contracts/outcome'
|
3
5
|
|
4
6
|
module Interactor
|
5
7
|
module Contracts
|
@@ -28,7 +30,7 @@ module Interactor
|
|
28
30
|
# @param [Block] term the term to add to the terms
|
29
31
|
# @return [void]
|
30
32
|
def add(&term)
|
31
|
-
@terms = Dry::Validation.Schema(@terms, {:
|
33
|
+
@terms = Dry::Validation.Schema(@terms, { build: false }, &term)
|
32
34
|
end
|
33
35
|
|
34
36
|
# Validates the terms against a given context
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interactor-contracts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Herold
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-validation
|
@@ -42,14 +42,14 @@ dependencies:
|
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.11'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.11'
|
55
55
|
description: Add contacts to your interactors
|
@@ -93,10 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 2.6.10
|
96
|
+
rubygems_version: 3.0.3
|
98
97
|
signing_key:
|
99
98
|
specification_version: 4
|
100
99
|
summary: Add contacts to your interactors
|
101
100
|
test_files: []
|
102
|
-
has_rdoc:
|