pragma-operation 1.2.3 → 1.3.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
2
  SHA1:
3
- metadata.gz: de7f671cdcc96da6dcdfbeb86fe5fb18b779648b
4
- data.tar.gz: 7114511c8435298744b6cc013c631ebc11a342f6
3
+ metadata.gz: 39e11fbcfbe2c2df5eed59358aa1a84a79675083
4
+ data.tar.gz: aa39dec0b423e58f84a059a768ef9fa2a525a851
5
5
  SHA512:
6
- metadata.gz: 8a0ce612dbb5b9922a102ea07c94f1369306ef46c79187789d1d3ea89b0a84c67fdb55d2e508a922b6a7689a5e770417b11fce102e221de8d426764c20689289
7
- data.tar.gz: 16a91000d9daa183a4f13b83187c381f7cee3e5ee0bc06dc555f07cc472b6a36fa2298c709d59c3b77597f94573dca2d0181c418d4bdc52ed2b2151cc258ac54
6
+ metadata.gz: aa9fc148a5a071c1114a65c263356cf4255af745cc72493d9c46e98e4b5fdf828efd4ed71a527442452d5919b03b69638e8bef8852f43a48e2728c28b1b00f9b
7
+ data.tar.gz: f3b7c56270dd51780b29546d94cbef55fbc7bf45a3c2e7c94446530acdad78c812cf81c5aa0f9cf5ed77f495a1fb930350eaaf1284b5a638532f4b4308e67f5a
@@ -91,18 +91,41 @@ module Pragma
91
91
  end
92
92
  # rubocop:enable Metrics/LineLength
93
93
 
94
- return if validate(contract)
94
+ respond_with_validation_errors!(contract) unless validate(contract)
95
+ end
96
+
97
+ # Sets a response suitable for reporting validation errors.
98
+ #
99
+ # The response will be a 422 Unprocessable Entity, contain the +error_type+, +error_message+
100
+ # and +meta+ keys. +meta.errors+ will contain the validation errors.
101
+ #
102
+ # @param validatable [Object] a validatable object
103
+ def respond_with_validation_errors(validatable)
104
+ respond_with validation_errors_response(validatable)
105
+ end
106
+
107
+ # Same as {#respond_with_validation_errors}, but also halts the execution of the operation.
108
+ #
109
+ # @param validatable [Object] a validatable object
110
+ #
111
+ # @see #respond_with_validation_errors
112
+ def respond_with_validation_errors!(validatable)
113
+ respond_with! validation_errors_response(validatable)
114
+ end
115
+
116
+ private
95
117
 
96
- respond_with!(
118
+ def validation_errors_response(validatable)
119
+ {
97
120
  status: :unprocessable_entity,
98
121
  resource: {
99
122
  error_type: :contract_not_respected,
100
123
  error_message: 'The contract for this operation was not respected.',
101
124
  meta: {
102
- errors: contract.errors.messages
125
+ errors: validatable.errors.messages
103
126
  }
104
127
  }
105
- )
128
+ }
106
129
  end
107
130
  end
108
131
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Pragma
3
3
  module Operation
4
- VERSION = '1.2.3'
4
+ VERSION = '1.3.0'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragma-operation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Desantis