treaty 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 +4 -4
- data/README.md +104 -16
- data/config/locales/en.yml +96 -0
- data/lib/treaty/attribute/base.rb +10 -8
- data/lib/treaty/attribute/builder/base.rb +3 -2
- data/lib/treaty/attribute/option/base.rb +1 -0
- data/lib/treaty/attribute/option/modifiers/as_modifier.rb +3 -2
- data/lib/treaty/attribute/option/validators/inclusion_validator.rb +6 -6
- data/lib/treaty/attribute/option/validators/required_validator.rb +2 -4
- data/lib/treaty/attribute/option/validators/type_validator.rb +19 -13
- data/lib/treaty/attribute/option_normalizer.rb +2 -1
- data/lib/treaty/attribute/option_orchestrator.rb +4 -3
- data/lib/treaty/attribute/validation/base.rb +2 -3
- data/lib/treaty/attribute/validation/nested_array_validator.rb +12 -7
- data/lib/treaty/attribute/validation/nested_transformer.rb +13 -7
- data/lib/treaty/attribute/validation/orchestrator/base.rb +2 -4
- data/lib/treaty/controller/dsl.rb +2 -2
- data/lib/treaty/exceptions/base.rb +39 -0
- data/lib/treaty/exceptions/class_name.rb +39 -0
- data/lib/treaty/exceptions/deprecated.rb +46 -0
- data/lib/treaty/exceptions/execution.rb +58 -0
- data/lib/treaty/exceptions/method_name.rb +47 -0
- data/lib/treaty/exceptions/nested_attributes.rb +57 -0
- data/lib/treaty/exceptions/not_implemented.rb +32 -0
- data/lib/treaty/exceptions/strategy.rb +55 -0
- data/lib/treaty/exceptions/unexpected.rb +62 -0
- data/lib/treaty/exceptions/validation.rb +89 -0
- data/lib/treaty/info/builder.rb +3 -3
- data/lib/treaty/request/attribute/attribute.rb +1 -1
- data/lib/treaty/response/attribute/attribute.rb +1 -1
- data/lib/treaty/strategy.rb +2 -2
- data/lib/treaty/version.rb +1 -1
- data/lib/treaty/versions/execution/request.rb +24 -28
- data/lib/treaty/versions/factory.rb +3 -4
- data/lib/treaty/versions/resolver.rb +3 -6
- metadata +21 -5
|
@@ -56,9 +56,8 @@ module Treaty
|
|
|
56
56
|
string_executor = executor.to_s
|
|
57
57
|
|
|
58
58
|
if string_executor.empty?
|
|
59
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
60
59
|
raise Treaty::Exceptions::Execution,
|
|
61
|
-
"
|
|
60
|
+
I18n.t("treaty.execution.executor_empty")
|
|
62
61
|
end
|
|
63
62
|
|
|
64
63
|
constant_name = normalize_constant_name(executor)
|
|
@@ -66,15 +65,12 @@ module Treaty
|
|
|
66
65
|
begin
|
|
67
66
|
constant_name.constantize
|
|
68
67
|
rescue NameError
|
|
69
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
70
68
|
raise Treaty::Exceptions::Execution,
|
|
71
|
-
"
|
|
69
|
+
I18n.t("treaty.execution.executor_not_found", class_name: constant_name)
|
|
72
70
|
end
|
|
73
71
|
else
|
|
74
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
75
72
|
raise Treaty::Exceptions::Execution,
|
|
76
|
-
"
|
|
77
|
-
"Expected Proc, Class, String, or Symbol"
|
|
73
|
+
I18n.t("treaty.execution.executor_invalid_type", type: executor.class)
|
|
78
74
|
end
|
|
79
75
|
end
|
|
80
76
|
|
|
@@ -96,39 +92,40 @@ module Treaty
|
|
|
96
92
|
def execute_proc
|
|
97
93
|
executor.call(params: @validated_params)
|
|
98
94
|
rescue StandardError => e
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
raise Treaty::Exceptions::Execution,
|
|
96
|
+
I18n.t("treaty.execution.proc_error", message: e.message)
|
|
101
97
|
end
|
|
102
98
|
|
|
103
|
-
def execute_servactory
|
|
99
|
+
def execute_servactory # rubocop:disable Metrics/MethodLength
|
|
104
100
|
executor.call!(params: @validated_params)
|
|
105
101
|
rescue ApplicationService::Exceptions::Input => e
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
rescue ApplicationService::Exceptions::Internal => e
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
rescue ApplicationService::Exceptions::Output => e
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
rescue ApplicationService::Exceptions::Failure => e
|
|
115
|
-
|
|
116
|
-
|
|
102
|
+
raise Treaty::Exceptions::Execution,
|
|
103
|
+
I18n.t("treaty.execution.servactory_input_error", message: e.message)
|
|
104
|
+
rescue ApplicationService::Exceptions::Internal => e
|
|
105
|
+
raise Treaty::Exceptions::Execution,
|
|
106
|
+
I18n.t("treaty.execution.servactory_internal_error", message: e.message)
|
|
107
|
+
rescue ApplicationService::Exceptions::Output => e
|
|
108
|
+
raise Treaty::Exceptions::Execution,
|
|
109
|
+
I18n.t("treaty.execution.servactory_output_error", message: e.message)
|
|
110
|
+
rescue ApplicationService::Exceptions::Failure => e
|
|
111
|
+
raise Treaty::Exceptions::Execution,
|
|
112
|
+
I18n.t("treaty.execution.servactory_failure_error", message: e.message)
|
|
117
113
|
end
|
|
118
114
|
|
|
119
|
-
def execute_regular_class
|
|
115
|
+
def execute_regular_class # rubocop:disable Metrics/MethodLength
|
|
120
116
|
method_name = @version_factory.executor.method
|
|
121
117
|
|
|
122
118
|
unless executor.respond_to?(method_name)
|
|
123
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
124
119
|
raise Treaty::Exceptions::Execution,
|
|
125
|
-
"
|
|
120
|
+
I18n.t("treaty.execution.method_not_found",
|
|
121
|
+
method: method_name,
|
|
122
|
+
class_name: executor)
|
|
126
123
|
end
|
|
127
124
|
|
|
128
125
|
executor.public_send(method_name, params: @validated_params)
|
|
129
126
|
rescue StandardError => e
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
raise Treaty::Exceptions::Execution,
|
|
128
|
+
I18n.t("treaty.execution.regular_service_error", message: e.message)
|
|
132
129
|
end
|
|
133
130
|
|
|
134
131
|
########################################################################
|
|
@@ -136,9 +133,8 @@ module Treaty
|
|
|
136
133
|
########################################################################
|
|
137
134
|
|
|
138
135
|
def raise_executor_missing_error!
|
|
139
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
140
136
|
raise Treaty::Exceptions::Execution,
|
|
141
|
-
"
|
|
137
|
+
I18n.t("treaty.execution.executor_missing", version: @version_factory.version)
|
|
142
138
|
end
|
|
143
139
|
|
|
144
140
|
def servactory_service?
|
|
@@ -73,16 +73,15 @@ module Treaty
|
|
|
73
73
|
return @default_result
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
77
76
|
raise Treaty::Exceptions::Validation,
|
|
78
|
-
"
|
|
77
|
+
I18n.t("treaty.versioning.factory.invalid_default_option", type: @default_result.class)
|
|
79
78
|
end
|
|
80
79
|
|
|
81
80
|
##########################################################################
|
|
82
81
|
|
|
83
82
|
def method_missing(name, *, &_block)
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
raise Treaty::Exceptions::MethodName,
|
|
84
|
+
I18n.t("treaty.versioning.factory.unknown_method", method: name)
|
|
86
85
|
end
|
|
87
86
|
|
|
88
87
|
def respond_to_missing?(name, *)
|
|
@@ -51,21 +51,18 @@ module Treaty
|
|
|
51
51
|
##########################################################################
|
|
52
52
|
|
|
53
53
|
def raise_current_version_not_found!
|
|
54
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
55
54
|
raise Treaty::Exceptions::Validation,
|
|
56
|
-
"
|
|
55
|
+
I18n.t("treaty.versioning.resolver.current_version_required")
|
|
57
56
|
end
|
|
58
57
|
|
|
59
58
|
def raise_version_not_found!
|
|
60
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
61
59
|
raise Treaty::Exceptions::Validation,
|
|
62
|
-
"
|
|
60
|
+
I18n.t("treaty.versioning.resolver.version_not_found", version: current_version)
|
|
63
61
|
end
|
|
64
62
|
|
|
65
63
|
def raise_version_deprecated!
|
|
66
|
-
# TODO: It is necessary to implement a translation system (I18n).
|
|
67
64
|
raise Treaty::Exceptions::Deprecated,
|
|
68
|
-
"
|
|
65
|
+
I18n.t("treaty.versioning.resolver.version_deprecated", version: current_version)
|
|
69
66
|
end
|
|
70
67
|
end
|
|
71
68
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: treaty
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anton Sokolov
|
|
@@ -9,6 +9,20 @@ bindir: bin
|
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: i18n
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.14'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.14'
|
|
12
26
|
- !ruby/object:Gem::Dependency
|
|
13
27
|
name: rails
|
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -121,8 +135,8 @@ dependencies:
|
|
|
121
135
|
- - ">="
|
|
122
136
|
- !ruby/object:Gem::Version
|
|
123
137
|
version: '0.9'
|
|
124
|
-
description:
|
|
125
|
-
|
|
138
|
+
description: A Ruby library for defining and managing REST API contracts with versioning
|
|
139
|
+
support
|
|
126
140
|
email:
|
|
127
141
|
- profox.rus@gmail.com
|
|
128
142
|
executables: []
|
|
@@ -131,6 +145,7 @@ extra_rdoc_files: []
|
|
|
131
145
|
files:
|
|
132
146
|
- README.md
|
|
133
147
|
- Rakefile
|
|
148
|
+
- config/locales/en.yml
|
|
134
149
|
- lib/treaty.rb
|
|
135
150
|
- lib/treaty/attribute/base.rb
|
|
136
151
|
- lib/treaty/attribute/builder/base.rb
|
|
@@ -165,6 +180,7 @@ files:
|
|
|
165
180
|
- lib/treaty/exceptions/execution.rb
|
|
166
181
|
- lib/treaty/exceptions/method_name.rb
|
|
167
182
|
- lib/treaty/exceptions/nested_attributes.rb
|
|
183
|
+
- lib/treaty/exceptions/not_implemented.rb
|
|
168
184
|
- lib/treaty/exceptions/strategy.rb
|
|
169
185
|
- lib/treaty/exceptions/unexpected.rb
|
|
170
186
|
- lib/treaty/exceptions/validation.rb
|
|
@@ -222,6 +238,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
222
238
|
requirements: []
|
|
223
239
|
rubygems_version: 3.6.9
|
|
224
240
|
specification_version: 4
|
|
225
|
-
summary:
|
|
226
|
-
|
|
241
|
+
summary: A Ruby library for defining and managing REST API contracts with versioning
|
|
242
|
+
support
|
|
227
243
|
test_files: []
|