pragma-operation 1.2.3 → 1.3.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 +4 -4
- data/lib/pragma/operation/validation.rb +27 -4
- data/lib/pragma/operation/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39e11fbcfbe2c2df5eed59358aa1a84a79675083
|
4
|
+
data.tar.gz: aa39dec0b423e58f84a059a768ef9fa2a525a851
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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:
|
125
|
+
errors: validatable.errors.messages
|
103
126
|
}
|
104
127
|
}
|
105
|
-
|
128
|
+
}
|
106
129
|
end
|
107
130
|
end
|
108
131
|
end
|