treaty 0.11.0 → 0.13.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 +14 -3
- data/config/locales/en.yml +32 -5
- data/lib/treaty/attribute/option/base.rb +3 -3
- data/lib/treaty/attribute/option/modifiers/cast_modifier.rb +244 -0
- data/lib/treaty/attribute/option/modifiers/transform_modifier.rb +111 -0
- data/lib/treaty/attribute/option/registry_initializer.rb +4 -0
- data/lib/treaty/attribute/option_normalizer.rb +2 -1
- data/lib/treaty/attribute/validation/base.rb +6 -24
- data/lib/treaty/attribute/validation/nested_transformer.rb +7 -6
- data/lib/treaty/configuration.rb +1 -1
- data/lib/treaty/context/callable.rb +7 -5
- data/lib/treaty/context/workspace.rb +4 -0
- data/lib/treaty/controller/dsl.rb +25 -3
- data/lib/treaty/exceptions/base.rb +0 -1
- data/lib/treaty/exceptions/inventory.rb +70 -0
- data/lib/treaty/exceptions/method_name.rb +0 -2
- data/lib/treaty/executor/inventory.rb +122 -0
- data/lib/treaty/info/rest/builder.rb +0 -1
- data/lib/treaty/inventory/collection.rb +71 -0
- data/lib/treaty/inventory/factory.rb +91 -0
- data/lib/treaty/inventory/inventory.rb +92 -0
- data/lib/treaty/request/validator.rb +2 -7
- data/lib/treaty/response/validator.rb +1 -5
- data/lib/treaty/version.rb +1 -1
- data/lib/treaty/versions/execution/request.rb +29 -4
- data/lib/treaty/versions/factory.rb +0 -6
- data/lib/treaty/versions/workspace.rb +3 -1
- metadata +8 -3
- data/lib/treaty/exceptions/strategy.rb +0 -63
- data/lib/treaty/strategy.rb +0 -31
|
@@ -5,7 +5,7 @@ module Treaty
|
|
|
5
5
|
module Workspace
|
|
6
6
|
private
|
|
7
7
|
|
|
8
|
-
def call!(version:, params:, **) # rubocop:disable Metrics/MethodLength
|
|
8
|
+
def call!(context:, inventory:, version:, params:, **) # rubocop:disable Metrics/MethodLength
|
|
9
9
|
super
|
|
10
10
|
|
|
11
11
|
version_factory = Resolver.resolve!(
|
|
@@ -19,6 +19,8 @@ module Treaty
|
|
|
19
19
|
)
|
|
20
20
|
|
|
21
21
|
executor_result = Execution::Request.execute!(
|
|
22
|
+
context:,
|
|
23
|
+
inventory:,
|
|
22
24
|
version_factory:,
|
|
23
25
|
validated_params:
|
|
24
26
|
)
|
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.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anton Sokolov
|
|
@@ -156,7 +156,9 @@ files:
|
|
|
156
156
|
- lib/treaty/attribute/helper_mapper.rb
|
|
157
157
|
- lib/treaty/attribute/option/base.rb
|
|
158
158
|
- lib/treaty/attribute/option/modifiers/as_modifier.rb
|
|
159
|
+
- lib/treaty/attribute/option/modifiers/cast_modifier.rb
|
|
159
160
|
- lib/treaty/attribute/option/modifiers/default_modifier.rb
|
|
161
|
+
- lib/treaty/attribute/option/modifiers/transform_modifier.rb
|
|
160
162
|
- lib/treaty/attribute/option/registry.rb
|
|
161
163
|
- lib/treaty/attribute/option/registry_initializer.rb
|
|
162
164
|
- lib/treaty/attribute/option/validators/format_validator.rb
|
|
@@ -183,22 +185,26 @@ files:
|
|
|
183
185
|
- lib/treaty/exceptions/class_name.rb
|
|
184
186
|
- lib/treaty/exceptions/deprecated.rb
|
|
185
187
|
- lib/treaty/exceptions/execution.rb
|
|
188
|
+
- lib/treaty/exceptions/inventory.rb
|
|
186
189
|
- lib/treaty/exceptions/method_name.rb
|
|
187
190
|
- lib/treaty/exceptions/nested_attributes.rb
|
|
188
191
|
- lib/treaty/exceptions/not_implemented.rb
|
|
189
192
|
- lib/treaty/exceptions/specified_version_not_found.rb
|
|
190
|
-
- lib/treaty/exceptions/strategy.rb
|
|
191
193
|
- lib/treaty/exceptions/unexpected.rb
|
|
192
194
|
- lib/treaty/exceptions/validation.rb
|
|
193
195
|
- lib/treaty/exceptions/version_default_deprecated_conflict.rb
|
|
194
196
|
- lib/treaty/exceptions/version_multiple_defaults.rb
|
|
195
197
|
- lib/treaty/exceptions/version_not_found.rb
|
|
198
|
+
- lib/treaty/executor/inventory.rb
|
|
196
199
|
- lib/treaty/info/entity/builder.rb
|
|
197
200
|
- lib/treaty/info/entity/dsl.rb
|
|
198
201
|
- lib/treaty/info/entity/result.rb
|
|
199
202
|
- lib/treaty/info/rest/builder.rb
|
|
200
203
|
- lib/treaty/info/rest/dsl.rb
|
|
201
204
|
- lib/treaty/info/rest/result.rb
|
|
205
|
+
- lib/treaty/inventory/collection.rb
|
|
206
|
+
- lib/treaty/inventory/factory.rb
|
|
207
|
+
- lib/treaty/inventory/inventory.rb
|
|
202
208
|
- lib/treaty/request/attribute/attribute.rb
|
|
203
209
|
- lib/treaty/request/attribute/builder.rb
|
|
204
210
|
- lib/treaty/request/entity.rb
|
|
@@ -210,7 +216,6 @@ files:
|
|
|
210
216
|
- lib/treaty/response/factory.rb
|
|
211
217
|
- lib/treaty/response/validator.rb
|
|
212
218
|
- lib/treaty/result.rb
|
|
213
|
-
- lib/treaty/strategy.rb
|
|
214
219
|
- lib/treaty/support/loader.rb
|
|
215
220
|
- lib/treaty/version.rb
|
|
216
221
|
- lib/treaty/versions/collection.rb
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Treaty
|
|
4
|
-
module Exceptions
|
|
5
|
-
# Raised when an unknown or invalid strategy is specified
|
|
6
|
-
#
|
|
7
|
-
# ## Purpose
|
|
8
|
-
#
|
|
9
|
-
# Ensures only valid strategy types are used in version definitions.
|
|
10
|
-
# Prevents typos and invalid strategy configurations.
|
|
11
|
-
#
|
|
12
|
-
# ## Usage
|
|
13
|
-
#
|
|
14
|
-
# Raised when specifying an invalid strategy in version definition:
|
|
15
|
-
#
|
|
16
|
-
# ```ruby
|
|
17
|
-
# version 1 do
|
|
18
|
-
# strategy Treaty::Strategy::ADAPTER # Valid
|
|
19
|
-
# strategy Treaty::Strategy::DIRECT # Valid
|
|
20
|
-
#
|
|
21
|
-
# strategy :invalid_strategy # Raises Treaty::Exceptions::Strategy
|
|
22
|
-
# end
|
|
23
|
-
# ```
|
|
24
|
-
#
|
|
25
|
-
# ## Valid Strategies
|
|
26
|
-
#
|
|
27
|
-
# Only two strategies are supported:
|
|
28
|
-
#
|
|
29
|
-
# - `Treaty::Strategy::DIRECT` - Direct pass-through mode
|
|
30
|
-
# - No transformation between service and response
|
|
31
|
-
# - Service output becomes response output directly
|
|
32
|
-
# - Faster but less flexible
|
|
33
|
-
#
|
|
34
|
-
# - `Treaty::Strategy::ADAPTER` - Adapter mode (default)
|
|
35
|
-
# - Transforms service output to match response schema
|
|
36
|
-
# - Validates and adapts data structure
|
|
37
|
-
# - More flexible, recommended for most cases
|
|
38
|
-
#
|
|
39
|
-
# ## Integration
|
|
40
|
-
#
|
|
41
|
-
# Can be rescued by application controllers:
|
|
42
|
-
#
|
|
43
|
-
# ```ruby
|
|
44
|
-
# rescue_from Treaty::Exceptions::Strategy, with: :render_strategy_error
|
|
45
|
-
#
|
|
46
|
-
# def render_strategy_error(exception)
|
|
47
|
-
# render json: { error: exception.message }, status: :internal_server_error
|
|
48
|
-
# end
|
|
49
|
-
# ```
|
|
50
|
-
#
|
|
51
|
-
# ## Default Behavior
|
|
52
|
-
#
|
|
53
|
-
# If no strategy is specified, ADAPTER is used by default:
|
|
54
|
-
#
|
|
55
|
-
# ```ruby
|
|
56
|
-
# version 1 do
|
|
57
|
-
# # strategy defaults to Treaty::Strategy::ADAPTER
|
|
58
|
-
# end
|
|
59
|
-
# ```
|
|
60
|
-
class Strategy < Base
|
|
61
|
-
end
|
|
62
|
-
end
|
|
63
|
-
end
|
data/lib/treaty/strategy.rb
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Treaty
|
|
4
|
-
class Strategy
|
|
5
|
-
DIRECT = :direct
|
|
6
|
-
ADAPTER = :adapter
|
|
7
|
-
|
|
8
|
-
LIST = [DIRECT, ADAPTER].freeze
|
|
9
|
-
|
|
10
|
-
attr_reader :code
|
|
11
|
-
|
|
12
|
-
def initialize(code)
|
|
13
|
-
@code = code
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def validate!
|
|
17
|
-
return self if LIST.include?(@code)
|
|
18
|
-
|
|
19
|
-
raise Treaty::Exceptions::Strategy,
|
|
20
|
-
I18n.t("treaty.versioning.strategy.unknown", strategy: @code)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def direct?
|
|
24
|
-
@code == DIRECT
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def adapter?
|
|
28
|
-
@code == ADAPTER
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|