interactor-contracts 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: f4b6a4b9a1473818e3af68c266630d617bf119a6
4
- data.tar.gz: 21a9105f05f823a824545aa231669c7215b6af34
2
+ SHA256:
3
+ metadata.gz: 155341334dd614cae42bd73f08e6791280ba8481ce82fb99c1803ec6efff45b4
4
+ data.tar.gz: e57c5cd09039e621a0df9bec33b6fcfc98b543b5d99eaf0caebc2aeb1069abdf
5
5
  SHA512:
6
- metadata.gz: ab017960b801b150397d026f4754eb231e3128c96e7119f1a3764d3bcc3cdf70cf2640ea630558b4433761f15be64c6a3200a3bcf95f36bc8db3f564be5c8082
7
- data.tar.gz: 76c7ba6f0390f18ffebac61dfb14863d9f0920255c930dce9a4dbb3e22f498b9690ae115453a2075d3baf14345a1f6881b3b41072520e6778980fc30d7ec795b
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
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require File.expand_path("../lib/interactor/contracts/version", __FILE__)
3
+ require File.expand_path('../lib/interactor/contracts/version', __FILE__)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "interactor-contracts"
6
+ spec.name = 'interactor-contracts'
7
7
  spec.version = Interactor::Contracts::VERSION
8
- spec.authors = ["Michael Herold"]
9
- spec.email = ["michael.j.herold@gmail.com"]
8
+ spec.authors = ['Michael Herold']
9
+ spec.email = ['michael.j.herold@gmail.com']
10
10
 
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"
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(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"]
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 "dry-validation", "~> 0.10"
22
- spec.add_dependency "interactor", "~> 3"
21
+ spec.add_dependency 'dry-validation', '~> 0.10'
22
+ spec.add_dependency 'interactor', '~> 3'
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency 'bundler', '> 1.11'
25
25
  end
@@ -1,2 +1,3 @@
1
- # rubocop:disable Style/FileName
2
- require "interactor/contracts"
1
+ # frozen_string_literal: true
2
+
3
+ require 'interactor/contracts'
@@ -1,7 +1,9 @@
1
- require "dry-validation"
2
- require "interactor"
3
- require "interactor/contracts/dsl"
4
- require "interactor/contracts/errors"
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
- fail NotAnInteractor, "#{descendant} does not include `Interactor'"
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
- unless outcome.success?
41
- contract.consequences.each do |handler|
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
- require "delegate"
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
- reduce({}) do |result, (property, messages)|
39
- result[property] = Array(result[property]) | messages
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
- alias_method :to_h, :to_hash
50
+ alias to_h to_hash
44
51
  end
45
52
  end
46
53
  end
@@ -1,4 +1,6 @@
1
- require "interactor/contracts/terms"
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
- require "interactor/contracts/contract"
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
- alias_method :defined_assurances_hook?, :defined_assurances_hook
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
- alias_method :defined_expectations_hook?, :defined_expectations_hook
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,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Interactor
2
4
  module Contracts
3
5
  # Base error class used for all errors within the gem.
@@ -1,6 +1,8 @@
1
- require "forwardable"
2
- require "interactor/contracts/breach"
3
- require "interactor/contracts/breach_set"
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(:full => true).map do |property, 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
- require "dry-validation"
2
- require "interactor/contracts/outcome"
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, {:build => false}, &term)
33
+ @terms = Dry::Validation.Schema(@terms, { build: false }, &term)
32
34
  end
33
35
 
34
36
  # Validates the terms against a given context
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Interactor
2
4
  module Contracts
3
- VERSION = "0.1.0".freeze
5
+ VERSION = '0.2.0'
4
6
  end
5
7
  end
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.1.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: 2017-02-25 00:00:00.000000000 Z
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
- rubyforge_project:
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: