treaty 0.3.0 → 0.5.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 +1 -1
- data/config/locales/en.yml +17 -1
- data/lib/treaty/context/callable.rb +4 -4
- data/lib/treaty/context/workspace.rb +2 -2
- data/lib/treaty/controller/dsl.rb +5 -1
- data/lib/treaty/exceptions/base.rb +1 -1
- data/lib/treaty/request/attribute/validator.rb +4 -4
- data/lib/treaty/request/factory.rb +2 -2
- data/lib/treaty/response/factory.rb +2 -2
- data/lib/treaty/version.rb +1 -1
- data/lib/treaty/versions/resolver.rb +6 -11
- data/lib/treaty/versions/workspace.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 289523f9463299cc9fa6a6bf8dc3b84226da537d100da9f9742dcadfd1cb910f
|
|
4
|
+
data.tar.gz: 4e5a37f32a79443bfd2550404b81705b23c19a55989d739ff835b4ffccac24b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 36d15ecb4de774f9e0fa6d268cf387eb23b384dfb5261371b05b24c84db82bb000e3740c5f7a6cc7ec1cfe2e934b2076026a4f677a8470d3b99c90da64b7f5df
|
|
7
|
+
data.tar.gz: f4142783c30b336124654d4b40968d2dc2b99614e90d2853e72924609e95464a8b0786ca78d36f3c6f0798478804ec9f01e132c7f76456421f968b615bc8fc62
|
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
[](https://rubygems.org/gems/treaty)
|
|
9
9
|
[](https://github.com/servactory/servactory/releases)
|
|
10
10
|
[](https://rubygems.org/gems/treaty)
|
|
11
|
-

|
|
11
|
+
[](https://www.ruby-lang.org)
|
|
12
12
|
|
|
13
13
|
</div>
|
|
14
14
|
|
data/config/locales/en.yml
CHANGED
|
@@ -55,6 +55,22 @@ en:
|
|
|
55
55
|
apply_defaults_not_implemented: "%{class} must implement #apply_defaults!"
|
|
56
56
|
process_nested_not_implemented: "%{class} must implement #process_nested_attributes"
|
|
57
57
|
|
|
58
|
+
# ============================================================================
|
|
59
|
+
# Request: Request definition and structure
|
|
60
|
+
# ============================================================================
|
|
61
|
+
request:
|
|
62
|
+
# Request factory DSL
|
|
63
|
+
factory:
|
|
64
|
+
unknown_method: "Unknown method '%{method}' in request definition. Use 'scope :name do ... end' to define request structure"
|
|
65
|
+
|
|
66
|
+
# ============================================================================
|
|
67
|
+
# Response: Response definition and structure
|
|
68
|
+
# ============================================================================
|
|
69
|
+
response:
|
|
70
|
+
# Response factory DSL
|
|
71
|
+
factory:
|
|
72
|
+
unknown_method: "Unknown method '%{method}' in response definition. Use 'scope :name do ... end' to define response structure"
|
|
73
|
+
|
|
58
74
|
# ============================================================================
|
|
59
75
|
# Versioning: API version management and resolution
|
|
60
76
|
# ============================================================================
|
|
@@ -68,7 +84,7 @@ en:
|
|
|
68
84
|
# Version factory
|
|
69
85
|
factory:
|
|
70
86
|
invalid_default_option: "Default option for version must be true, false, or a Proc, got: %{type}"
|
|
71
|
-
unknown_method: "Unknown method
|
|
87
|
+
unknown_method: "Unknown method '%{method}' in version definition. Available methods: summary, strategy, deprecated, request, response, delegate_to"
|
|
72
88
|
|
|
73
89
|
# Strategy validation
|
|
74
90
|
strategy:
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
module Treaty
|
|
4
4
|
module Context
|
|
5
5
|
module Callable
|
|
6
|
-
def call!(
|
|
6
|
+
def call!(version:, params:)
|
|
7
7
|
context = send(:new)
|
|
8
8
|
|
|
9
|
-
_call!(context,
|
|
9
|
+
_call!(context, version:, params:)
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
private
|
|
13
13
|
|
|
14
|
-
def _call!(context,
|
|
14
|
+
def _call!(context, version:, params:)
|
|
15
15
|
context.send(
|
|
16
16
|
:_call!,
|
|
17
|
-
|
|
17
|
+
version:,
|
|
18
18
|
params:,
|
|
19
19
|
collection_of_versions:
|
|
20
20
|
)
|
|
@@ -13,7 +13,7 @@ module Treaty
|
|
|
13
13
|
|
|
14
14
|
def treaty(action_name)
|
|
15
15
|
define_method(action_name) do
|
|
16
|
-
treaty = treaty_class.call!(
|
|
16
|
+
treaty = treaty_class.call!(version: treaty_version, params:)
|
|
17
17
|
|
|
18
18
|
render json: treaty.data, status: treaty.status
|
|
19
19
|
end
|
|
@@ -32,6 +32,10 @@ module Treaty
|
|
|
32
32
|
# TODO: Need to move `Treaty` to configuration.
|
|
33
33
|
self.class.name.sub(/Controller$/, "::#{action_name.to_s.classify}Treaty")
|
|
34
34
|
end
|
|
35
|
+
|
|
36
|
+
def treaty_version
|
|
37
|
+
Treaty::Engine.config.treaty.version.call(self)
|
|
38
|
+
end
|
|
35
39
|
end
|
|
36
40
|
end
|
|
37
41
|
end
|
|
@@ -15,7 +15,7 @@ module Treaty
|
|
|
15
15
|
#
|
|
16
16
|
# ```ruby
|
|
17
17
|
# begin
|
|
18
|
-
# Treaty::Base.call!(
|
|
18
|
+
# Treaty::Base.call!(version: treaty_version, params: params)
|
|
19
19
|
# rescue Treaty::Exceptions::Base => e
|
|
20
20
|
# # Catches any Treaty-specific exception
|
|
21
21
|
# handle_treaty_error(e)
|
|
@@ -8,10 +8,10 @@ module Treaty
|
|
|
8
8
|
new(...).validate!
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
def initialize(
|
|
11
|
+
def initialize(params:, version_factory:)
|
|
12
12
|
super(version_factory:)
|
|
13
13
|
|
|
14
|
-
@
|
|
14
|
+
@params = params
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def validate!
|
|
@@ -22,9 +22,9 @@ module Treaty
|
|
|
22
22
|
|
|
23
23
|
def request_data
|
|
24
24
|
@request_data ||= begin
|
|
25
|
-
@
|
|
25
|
+
@params.to_unsafe_h
|
|
26
26
|
rescue NoMethodError
|
|
27
|
-
@
|
|
27
|
+
@params
|
|
28
28
|
end
|
|
29
29
|
end
|
|
30
30
|
|
|
@@ -20,8 +20,8 @@ module Treaty
|
|
|
20
20
|
##########################################################################
|
|
21
21
|
|
|
22
22
|
def method_missing(name, *, &_block)
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
raise Treaty::Exceptions::MethodName,
|
|
24
|
+
I18n.t("treaty.request.factory.unknown_method", method: name)
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def respond_to_missing?(name, *)
|
|
@@ -26,8 +26,8 @@ module Treaty
|
|
|
26
26
|
##########################################################################
|
|
27
27
|
|
|
28
28
|
def method_missing(name, *, &_block)
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
raise Treaty::Exceptions::MethodName,
|
|
30
|
+
I18n.t("treaty.response.factory.unknown_method", method: name)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def respond_to_missing?(name, *)
|
data/lib/treaty/version.rb
CHANGED
|
@@ -7,8 +7,8 @@ module Treaty
|
|
|
7
7
|
new(...).resolve!
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
def initialize(
|
|
11
|
-
@
|
|
10
|
+
def initialize(current_version:, collection_of_versions:)
|
|
11
|
+
@current_version = current_version
|
|
12
12
|
@collection_of_versions = collection_of_versions
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -27,15 +27,10 @@ module Treaty
|
|
|
27
27
|
|
|
28
28
|
private
|
|
29
29
|
|
|
30
|
-
def current_version
|
|
31
|
-
@current_version ||=
|
|
32
|
-
Treaty::Engine.config.treaty.version.call(@controller)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
30
|
def version_factory
|
|
36
31
|
@version_factory ||=
|
|
37
32
|
@collection_of_versions.find do |factory|
|
|
38
|
-
factory.version.version == current_version
|
|
33
|
+
factory.version.version == @current_version
|
|
39
34
|
end
|
|
40
35
|
end
|
|
41
36
|
|
|
@@ -45,7 +40,7 @@ module Treaty
|
|
|
45
40
|
end
|
|
46
41
|
|
|
47
42
|
def current_version_blank?
|
|
48
|
-
current_version.to_s.strip.empty?
|
|
43
|
+
@current_version.to_s.strip.empty?
|
|
49
44
|
end
|
|
50
45
|
|
|
51
46
|
##########################################################################
|
|
@@ -57,12 +52,12 @@ module Treaty
|
|
|
57
52
|
|
|
58
53
|
def raise_version_not_found!
|
|
59
54
|
raise Treaty::Exceptions::Validation,
|
|
60
|
-
I18n.t("treaty.versioning.resolver.version_not_found", version: current_version)
|
|
55
|
+
I18n.t("treaty.versioning.resolver.version_not_found", version: @current_version)
|
|
61
56
|
end
|
|
62
57
|
|
|
63
58
|
def raise_version_deprecated!
|
|
64
59
|
raise Treaty::Exceptions::Deprecated,
|
|
65
|
-
I18n.t("treaty.versioning.resolver.version_deprecated", version: current_version)
|
|
60
|
+
I18n.t("treaty.versioning.resolver.version_deprecated", version: @current_version)
|
|
66
61
|
end
|
|
67
62
|
end
|
|
68
63
|
end
|
|
@@ -5,16 +5,16 @@ module Treaty
|
|
|
5
5
|
module Workspace
|
|
6
6
|
private
|
|
7
7
|
|
|
8
|
-
def call!(
|
|
8
|
+
def call!(version:, params:, **) # rubocop:disable Metrics/MethodLength
|
|
9
9
|
super
|
|
10
10
|
|
|
11
11
|
version_factory = Resolver.resolve!(
|
|
12
|
-
|
|
12
|
+
current_version: version,
|
|
13
13
|
collection_of_versions: @collection_of_versions
|
|
14
14
|
)
|
|
15
15
|
|
|
16
16
|
validated_params = Request::Attribute::Validator.validate!(
|
|
17
|
-
|
|
17
|
+
params:,
|
|
18
18
|
version_factory:
|
|
19
19
|
)
|
|
20
20
|
|