treaty 0.3.0 → 0.4.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/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/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: 9a2906d1588e4080f19519805a175efdc8df6178b4ea830f775b9ee1ddbd198d
|
|
4
|
+
data.tar.gz: 6ee3d6267f2b7df3d506ec4fcb9c8c5c7ba6a51eb813f5480ea7bfff0aaef2d1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 661e88b1f8cafb5912af30b56a31e1a39e499379bbc85edf966e0af53c22dee2907d6b4e3c6371564f2b4cbfd2f84f5f5cdbf8aff17ce909813548db0cc8b5a1
|
|
7
|
+
data.tar.gz: 4be479a20f9d77f59e4e6d09b67b052cf5fd474e87896d11307ece42d335d198f752a5af858f9f824d832f0507bb98add19d3b5ade406824c7cc662a07af08af
|
|
@@ -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
|
|
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
|
|