treaty 0.7.0 → 0.9.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 +5 -0
- data/config/locales/en.yml +8 -0
- data/lib/treaty/attribute/base.rb +13 -5
- data/lib/treaty/attribute/dsl.rb +90 -0
- data/lib/treaty/attribute/entity/attribute.rb +25 -0
- data/lib/treaty/attribute/entity/builder.rb +23 -0
- data/lib/treaty/attribute/option/base.rb +17 -1
- data/lib/treaty/attribute/option/modifiers/as_modifier.rb +5 -3
- data/lib/treaty/attribute/option/registry_initializer.rb +2 -0
- data/lib/treaty/attribute/option/validators/format_validator.rb +220 -0
- data/lib/treaty/attribute/option/validators/inclusion_validator.rb +20 -8
- data/lib/treaty/attribute/option/validators/required_validator.rb +8 -2
- data/lib/treaty/attribute/option/validators/type_validator.rb +51 -40
- data/lib/treaty/attribute/option_orchestrator.rb +7 -5
- data/lib/treaty/attribute/validation/nested_array_validator.rb +18 -12
- data/lib/treaty/attribute/validation/nested_transformer.rb +18 -12
- data/lib/treaty/base.rb +1 -1
- data/lib/treaty/controller/dsl.rb +4 -1
- data/lib/treaty/entity.rb +84 -0
- data/lib/treaty/info/entity/builder.rb +50 -0
- data/lib/treaty/info/entity/dsl.rb +28 -0
- data/lib/treaty/info/entity/result.rb +15 -0
- data/lib/treaty/info/rest/builder.rb +110 -0
- data/lib/treaty/info/rest/dsl.rb +28 -0
- data/lib/treaty/info/rest/result.rb +15 -0
- data/lib/treaty/request/attribute/attribute.rb +1 -0
- data/lib/treaty/request/attribute/builder.rb +1 -0
- data/lib/treaty/request/entity.rb +33 -0
- data/lib/treaty/request/factory.rb +61 -14
- data/lib/treaty/request/validator.rb +65 -0
- data/lib/treaty/response/attribute/attribute.rb +1 -0
- data/lib/treaty/response/attribute/builder.rb +1 -0
- data/lib/treaty/response/entity.rb +33 -0
- data/lib/treaty/response/factory.rb +61 -14
- data/lib/treaty/response/validator.rb +57 -0
- data/lib/treaty/version.rb +1 -1
- data/lib/treaty/versions/execution/request.rb +10 -5
- data/lib/treaty/versions/factory.rb +16 -5
- data/lib/treaty/versions/resolver.rb +8 -2
- data/lib/treaty/versions/workspace.rb +2 -2
- metadata +16 -8
- data/lib/treaty/info/builder.rb +0 -108
- data/lib/treaty/info/dsl.rb +0 -26
- data/lib/treaty/info/result.rb +0 -13
- data/lib/treaty/request/attribute/validation/orchestrator.rb +0 -19
- data/lib/treaty/request/attribute/validator.rb +0 -50
- data/lib/treaty/response/attribute/validation/orchestrator.rb +0 -19
- data/lib/treaty/response/attribute/validator.rb +0 -44
|
@@ -2,33 +2,80 @@
|
|
|
2
2
|
|
|
3
3
|
module Treaty
|
|
4
4
|
module Request
|
|
5
|
+
# Factory for creating request definitions.
|
|
6
|
+
#
|
|
7
|
+
# Supports two modes:
|
|
8
|
+
# 1. Block mode: Creates an anonymous Request::Entity class with the block
|
|
9
|
+
# 2. Entity mode: Uses a provided Entity class directly
|
|
10
|
+
#
|
|
11
|
+
# ## Block Mode
|
|
12
|
+
#
|
|
13
|
+
# ```ruby
|
|
14
|
+
# request do
|
|
15
|
+
# object :post do
|
|
16
|
+
# string :title
|
|
17
|
+
# end
|
|
18
|
+
# end
|
|
19
|
+
# ```
|
|
20
|
+
#
|
|
21
|
+
# ## Entity Mode
|
|
22
|
+
#
|
|
23
|
+
# ```ruby
|
|
24
|
+
# request PostRequestEntity
|
|
25
|
+
# ```
|
|
5
26
|
class Factory
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
27
|
+
# Uses a provided Entity class
|
|
28
|
+
#
|
|
29
|
+
# @param entity_class [Class] Entity class to use
|
|
30
|
+
# @return [void]
|
|
31
|
+
# @raise [Treaty::Exceptions::Validation] if entity_class is not a valid Treaty::Entity subclass
|
|
32
|
+
def use_entity(entity_class)
|
|
33
|
+
validate_entity_class!(entity_class)
|
|
34
|
+
@entity_class = entity_class
|
|
15
35
|
end
|
|
16
36
|
|
|
37
|
+
# Returns collection of attributes from the entity class
|
|
38
|
+
#
|
|
39
|
+
# @return [Collection] Collection of attributes
|
|
17
40
|
def collection_of_attributes
|
|
18
|
-
|
|
19
|
-
end
|
|
41
|
+
return Treaty::Attribute::Collection.new if @entity_class.nil?
|
|
20
42
|
|
|
21
|
-
|
|
43
|
+
@entity_class.collection_of_attributes
|
|
44
|
+
end
|
|
22
45
|
|
|
46
|
+
# Handles DSL methods for defining attributes
|
|
47
|
+
#
|
|
48
|
+
# This allows the factory to be used with method_missing
|
|
49
|
+
# for backwards compatibility with direct method calls.
|
|
50
|
+
# Creates an anonymous Request::Entity class on first use.
|
|
23
51
|
def method_missing(type, *helpers, **options, &block)
|
|
24
|
-
|
|
52
|
+
# If no entity class yet, create one
|
|
53
|
+
@entity_class ||= Class.new(Entity)
|
|
25
54
|
|
|
26
|
-
|
|
55
|
+
# Call the method on the entity class
|
|
56
|
+
@entity_class.public_send(type, *helpers, **options, &block)
|
|
27
57
|
end
|
|
28
58
|
|
|
29
59
|
def respond_to_missing?(name, *)
|
|
30
60
|
super
|
|
31
61
|
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
# Validates that the provided entity_class is a valid Treaty::Entity subclass
|
|
66
|
+
#
|
|
67
|
+
# @param entity_class [Class] Entity class to validate
|
|
68
|
+
# @raise [Treaty::Exceptions::Validation] if entity_class is not a valid Treaty::Entity subclass
|
|
69
|
+
def validate_entity_class!(entity_class)
|
|
70
|
+
return if entity_class.is_a?(Class) && entity_class < Treaty::Entity
|
|
71
|
+
|
|
72
|
+
raise Treaty::Exceptions::Validation,
|
|
73
|
+
I18n.t(
|
|
74
|
+
"treaty.request.factory.invalid_entity_class",
|
|
75
|
+
type: entity_class.class,
|
|
76
|
+
value: entity_class
|
|
77
|
+
)
|
|
78
|
+
end
|
|
32
79
|
end
|
|
33
80
|
end
|
|
34
81
|
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Treaty
|
|
4
|
+
module Request
|
|
5
|
+
# Validator for request data
|
|
6
|
+
class Validator
|
|
7
|
+
class << self
|
|
8
|
+
# Validates request parameters against the request definition
|
|
9
|
+
#
|
|
10
|
+
# @param params [Hash] Request parameters to validate
|
|
11
|
+
# @param version_factory [Versions::Factory] Version factory with request definition
|
|
12
|
+
# @return [Hash] Validated and transformed parameters
|
|
13
|
+
def validate!(params:, version_factory:)
|
|
14
|
+
new(params:, version_factory:).validate!
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def initialize(params:, version_factory:)
|
|
19
|
+
@params = params
|
|
20
|
+
@version_factory = version_factory
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def validate!
|
|
24
|
+
validate_request_attributes!
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def request_data
|
|
30
|
+
@request_data ||= begin
|
|
31
|
+
@params.to_unsafe_h
|
|
32
|
+
rescue NoMethodError
|
|
33
|
+
@params
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def validate_request_attributes! # rubocop:disable Metrics/MethodLength
|
|
38
|
+
return request_data unless adapter_strategy?
|
|
39
|
+
return request_data unless request_attributes_exist?
|
|
40
|
+
|
|
41
|
+
# For adapter strategy with attributes defined:
|
|
42
|
+
orchestrator_class = Class.new(Treaty::Attribute::Validation::Orchestrator::Base) do
|
|
43
|
+
define_method(:collection_of_attributes) do
|
|
44
|
+
@version_factory.request_factory.collection_of_attributes
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
orchestrator_class.validate!(
|
|
49
|
+
version_factory: @version_factory,
|
|
50
|
+
data: request_data
|
|
51
|
+
)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def adapter_strategy?
|
|
55
|
+
!@version_factory.strategy_instance.direct?
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def request_attributes_exist?
|
|
59
|
+
return false if @version_factory.request_factory&.collection_of_attributes&.empty?
|
|
60
|
+
|
|
61
|
+
@version_factory.request_factory.collection_of_attributes.exists?
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Treaty
|
|
4
|
+
module Response
|
|
5
|
+
# Entity class for response definitions.
|
|
6
|
+
# Attributes are optional by default.
|
|
7
|
+
#
|
|
8
|
+
# This class is used internally when defining response blocks.
|
|
9
|
+
# When you write a response block, Treaty creates an anonymous
|
|
10
|
+
# class based on Response::Entity.
|
|
11
|
+
class Entity
|
|
12
|
+
include Treaty::Attribute::DSL
|
|
13
|
+
|
|
14
|
+
class << self
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
# Creates a Response::Attribute::Attribute for this Response::Entity class
|
|
18
|
+
#
|
|
19
|
+
# @return [Response::Attribute::Attribute] Created attribute instance
|
|
20
|
+
def create_attribute(name, type, *helpers, nesting_level:, **options, &block)
|
|
21
|
+
Attribute::Attribute.new(
|
|
22
|
+
name,
|
|
23
|
+
type,
|
|
24
|
+
*helpers,
|
|
25
|
+
nesting_level:,
|
|
26
|
+
**options,
|
|
27
|
+
&block
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
module Treaty
|
|
4
4
|
module Response
|
|
5
|
+
# Factory for creating response definitions.
|
|
6
|
+
#
|
|
7
|
+
# Supports two modes:
|
|
8
|
+
# 1. Block mode: Creates an anonymous Response::Entity class with the block
|
|
9
|
+
# 2. Entity mode: Uses a provided Entity class directly
|
|
10
|
+
#
|
|
11
|
+
# ## Block Mode
|
|
12
|
+
#
|
|
13
|
+
# ```ruby
|
|
14
|
+
# response 200 do
|
|
15
|
+
# object :post do
|
|
16
|
+
# string :id
|
|
17
|
+
# end
|
|
18
|
+
# end
|
|
19
|
+
# ```
|
|
20
|
+
#
|
|
21
|
+
# ## Entity Mode
|
|
22
|
+
#
|
|
23
|
+
# ```ruby
|
|
24
|
+
# response 200, PostResponseEntity
|
|
25
|
+
# ```
|
|
5
26
|
class Factory
|
|
6
27
|
attr_reader :status
|
|
7
28
|
|
|
@@ -9,32 +30,58 @@ module Treaty
|
|
|
9
30
|
@status = status
|
|
10
31
|
end
|
|
11
32
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
33
|
+
# Uses a provided Entity class
|
|
34
|
+
#
|
|
35
|
+
# @param entity_class [Class] Entity class to use
|
|
36
|
+
# @return [void]
|
|
37
|
+
# @raise [Treaty::Exceptions::Validation] if entity_class is not a valid Treaty::Entity subclass
|
|
38
|
+
def use_entity(entity_class)
|
|
39
|
+
validate_entity_class!(entity_class)
|
|
40
|
+
@entity_class = entity_class
|
|
21
41
|
end
|
|
22
42
|
|
|
43
|
+
# Returns collection of attributes from the entity class
|
|
44
|
+
#
|
|
45
|
+
# @return [Collection] Collection of attributes
|
|
23
46
|
def collection_of_attributes
|
|
24
|
-
|
|
25
|
-
end
|
|
47
|
+
return Treaty::Attribute::Collection.new if @entity_class.nil?
|
|
26
48
|
|
|
27
|
-
|
|
49
|
+
@entity_class.collection_of_attributes
|
|
50
|
+
end
|
|
28
51
|
|
|
52
|
+
# Handles DSL methods for defining attributes
|
|
53
|
+
#
|
|
54
|
+
# This allows the factory to be used with method_missing
|
|
55
|
+
# for backwards compatibility with direct method calls.
|
|
56
|
+
# Creates an anonymous Response::Entity class on first use.
|
|
29
57
|
def method_missing(type, *helpers, **options, &block)
|
|
30
|
-
|
|
58
|
+
# If no entity class yet, create one
|
|
59
|
+
@entity_class ||= Class.new(Entity)
|
|
31
60
|
|
|
32
|
-
|
|
61
|
+
# Call the method on the entity class
|
|
62
|
+
@entity_class.public_send(type, *helpers, **options, &block)
|
|
33
63
|
end
|
|
34
64
|
|
|
35
65
|
def respond_to_missing?(name, *)
|
|
36
66
|
super
|
|
37
67
|
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
# Validates that the provided entity_class is a valid Treaty::Entity subclass
|
|
72
|
+
#
|
|
73
|
+
# @param entity_class [Class] Entity class to validate
|
|
74
|
+
# @raise [Treaty::Exceptions::Validation] if entity_class is not a valid Treaty::Entity subclass
|
|
75
|
+
def validate_entity_class!(entity_class)
|
|
76
|
+
return if entity_class.is_a?(Class) && entity_class < Treaty::Entity
|
|
77
|
+
|
|
78
|
+
raise Treaty::Exceptions::Validation,
|
|
79
|
+
I18n.t(
|
|
80
|
+
"treaty.response.factory.invalid_entity_class",
|
|
81
|
+
type: entity_class.class,
|
|
82
|
+
value: entity_class
|
|
83
|
+
)
|
|
84
|
+
end
|
|
38
85
|
end
|
|
39
86
|
end
|
|
40
87
|
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Treaty
|
|
4
|
+
module Response
|
|
5
|
+
# Validator for response data
|
|
6
|
+
class Validator
|
|
7
|
+
class << self
|
|
8
|
+
# Validates response data against the response definition
|
|
9
|
+
#
|
|
10
|
+
# @param response_data [Hash] Response data to validate
|
|
11
|
+
# @param version_factory [Versions::Factory] Version factory with response definition
|
|
12
|
+
# @return [Hash] Validated and transformed response data
|
|
13
|
+
def validate!(version_factory:, response_data: {})
|
|
14
|
+
new(version_factory:, response_data:).validate!
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def initialize(version_factory:, response_data: {})
|
|
19
|
+
@version_factory = version_factory
|
|
20
|
+
@response_data = response_data
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def validate!
|
|
24
|
+
validate_response_attributes!
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def validate_response_attributes!
|
|
30
|
+
return @response_data unless response_attributes_exist?
|
|
31
|
+
|
|
32
|
+
# Create orchestrator for both DIRECT and ADAPTER strategies
|
|
33
|
+
# Orchestrator filters data by attributes and performs transformation
|
|
34
|
+
orchestrator_class = Class.new(Treaty::Attribute::Validation::Orchestrator::Base) do
|
|
35
|
+
define_method(:collection_of_attributes) do
|
|
36
|
+
@version_factory.response_factory.collection_of_attributes
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
orchestrator_class.validate!(
|
|
41
|
+
version_factory: @version_factory,
|
|
42
|
+
data: @response_data
|
|
43
|
+
)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def adapter_strategy?
|
|
47
|
+
!@version_factory.strategy_instance.direct?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def response_attributes_exist?
|
|
51
|
+
return false if @version_factory.response_factory&.collection_of_attributes&.empty?
|
|
52
|
+
|
|
53
|
+
@version_factory.response_factory.collection_of_attributes.exists?
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
data/lib/treaty/version.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module Treaty
|
|
4
4
|
module Versions
|
|
5
5
|
module Execution
|
|
6
|
-
class Request
|
|
6
|
+
class Request # rubocop:disable Metrics/ClassLength
|
|
7
7
|
def self.execute!(...)
|
|
8
8
|
new(...).execute!
|
|
9
9
|
end
|
|
@@ -117,9 +117,11 @@ module Treaty
|
|
|
117
117
|
|
|
118
118
|
unless executor.respond_to?(method_name)
|
|
119
119
|
raise Treaty::Exceptions::Execution,
|
|
120
|
-
I18n.t(
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
I18n.t(
|
|
121
|
+
"treaty.execution.method_not_found",
|
|
122
|
+
method: method_name,
|
|
123
|
+
class_name: executor
|
|
124
|
+
)
|
|
123
125
|
end
|
|
124
126
|
|
|
125
127
|
executor.public_send(method_name, params: @validated_params)
|
|
@@ -134,7 +136,10 @@ module Treaty
|
|
|
134
136
|
|
|
135
137
|
def raise_executor_missing_error!
|
|
136
138
|
raise Treaty::Exceptions::Execution,
|
|
137
|
-
I18n.t(
|
|
139
|
+
I18n.t(
|
|
140
|
+
"treaty.execution.executor_missing",
|
|
141
|
+
version: @version_factory.version
|
|
142
|
+
)
|
|
138
143
|
end
|
|
139
144
|
|
|
140
145
|
def servactory_service?
|
|
@@ -48,16 +48,24 @@ module Treaty
|
|
|
48
48
|
@deprecated_result = result
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
def request(&block)
|
|
51
|
+
def request(entity_class = nil, &block)
|
|
52
52
|
@request_factory ||= Request::Factory.new
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
if entity_class.present?
|
|
55
|
+
@request_factory.use_entity(entity_class)
|
|
56
|
+
elsif block_given?
|
|
57
|
+
@request_factory.instance_eval(&block)
|
|
58
|
+
end
|
|
55
59
|
end
|
|
56
60
|
|
|
57
|
-
def response(status, &block)
|
|
61
|
+
def response(status, entity_class = nil, &block)
|
|
58
62
|
@response_factory ||= Response::Factory.new(status)
|
|
59
63
|
|
|
60
|
-
|
|
64
|
+
if entity_class.present?
|
|
65
|
+
@response_factory.use_entity(entity_class)
|
|
66
|
+
elsif block_given?
|
|
67
|
+
@response_factory.instance_eval(&block)
|
|
68
|
+
end
|
|
61
69
|
end
|
|
62
70
|
|
|
63
71
|
def delegate_to(executor, method = :call)
|
|
@@ -74,7 +82,10 @@ module Treaty
|
|
|
74
82
|
end
|
|
75
83
|
|
|
76
84
|
raise Treaty::Exceptions::Validation,
|
|
77
|
-
I18n.t(
|
|
85
|
+
I18n.t(
|
|
86
|
+
"treaty.versioning.factory.invalid_default_option",
|
|
87
|
+
type: @default_result.class
|
|
88
|
+
)
|
|
78
89
|
end
|
|
79
90
|
|
|
80
91
|
##########################################################################
|
|
@@ -52,12 +52,18 @@ module Treaty
|
|
|
52
52
|
|
|
53
53
|
def raise_version_not_found!
|
|
54
54
|
raise Treaty::Exceptions::Validation,
|
|
55
|
-
I18n.t(
|
|
55
|
+
I18n.t(
|
|
56
|
+
"treaty.versioning.resolver.version_not_found",
|
|
57
|
+
version: @current_version
|
|
58
|
+
)
|
|
56
59
|
end
|
|
57
60
|
|
|
58
61
|
def raise_version_deprecated!
|
|
59
62
|
raise Treaty::Exceptions::Deprecated,
|
|
60
|
-
I18n.t(
|
|
63
|
+
I18n.t(
|
|
64
|
+
"treaty.versioning.resolver.version_deprecated",
|
|
65
|
+
version: @current_version
|
|
66
|
+
)
|
|
61
67
|
end
|
|
62
68
|
end
|
|
63
69
|
end
|
|
@@ -13,7 +13,7 @@ module Treaty
|
|
|
13
13
|
collection_of_versions: @collection_of_versions
|
|
14
14
|
)
|
|
15
15
|
|
|
16
|
-
validated_params = Request::
|
|
16
|
+
validated_params = Request::Validator.validate!(
|
|
17
17
|
params:,
|
|
18
18
|
version_factory:
|
|
19
19
|
)
|
|
@@ -23,7 +23,7 @@ module Treaty
|
|
|
23
23
|
validated_params:
|
|
24
24
|
)
|
|
25
25
|
|
|
26
|
-
validated_response = Response::
|
|
26
|
+
validated_response = Response::Validator.validate!(
|
|
27
27
|
version_factory:,
|
|
28
28
|
response_data: executor_result
|
|
29
29
|
)
|
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.9.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Anton Sokolov
|
|
@@ -150,12 +150,16 @@ files:
|
|
|
150
150
|
- lib/treaty/attribute/base.rb
|
|
151
151
|
- lib/treaty/attribute/builder/base.rb
|
|
152
152
|
- lib/treaty/attribute/collection.rb
|
|
153
|
+
- lib/treaty/attribute/dsl.rb
|
|
154
|
+
- lib/treaty/attribute/entity/attribute.rb
|
|
155
|
+
- lib/treaty/attribute/entity/builder.rb
|
|
153
156
|
- lib/treaty/attribute/helper_mapper.rb
|
|
154
157
|
- lib/treaty/attribute/option/base.rb
|
|
155
158
|
- lib/treaty/attribute/option/modifiers/as_modifier.rb
|
|
156
159
|
- lib/treaty/attribute/option/modifiers/default_modifier.rb
|
|
157
160
|
- lib/treaty/attribute/option/registry.rb
|
|
158
161
|
- lib/treaty/attribute/option/registry_initializer.rb
|
|
162
|
+
- lib/treaty/attribute/option/validators/format_validator.rb
|
|
159
163
|
- lib/treaty/attribute/option/validators/inclusion_validator.rb
|
|
160
164
|
- lib/treaty/attribute/option/validators/required_validator.rb
|
|
161
165
|
- lib/treaty/attribute/option/validators/type_validator.rb
|
|
@@ -174,6 +178,7 @@ files:
|
|
|
174
178
|
- lib/treaty/context/workspace.rb
|
|
175
179
|
- lib/treaty/controller/dsl.rb
|
|
176
180
|
- lib/treaty/engine.rb
|
|
181
|
+
- lib/treaty/entity.rb
|
|
177
182
|
- lib/treaty/exceptions/base.rb
|
|
178
183
|
- lib/treaty/exceptions/class_name.rb
|
|
179
184
|
- lib/treaty/exceptions/deprecated.rb
|
|
@@ -184,19 +189,22 @@ files:
|
|
|
184
189
|
- lib/treaty/exceptions/strategy.rb
|
|
185
190
|
- lib/treaty/exceptions/unexpected.rb
|
|
186
191
|
- lib/treaty/exceptions/validation.rb
|
|
187
|
-
- lib/treaty/info/builder.rb
|
|
188
|
-
- lib/treaty/info/dsl.rb
|
|
189
|
-
- lib/treaty/info/result.rb
|
|
192
|
+
- lib/treaty/info/entity/builder.rb
|
|
193
|
+
- lib/treaty/info/entity/dsl.rb
|
|
194
|
+
- lib/treaty/info/entity/result.rb
|
|
195
|
+
- lib/treaty/info/rest/builder.rb
|
|
196
|
+
- lib/treaty/info/rest/dsl.rb
|
|
197
|
+
- lib/treaty/info/rest/result.rb
|
|
190
198
|
- lib/treaty/request/attribute/attribute.rb
|
|
191
199
|
- lib/treaty/request/attribute/builder.rb
|
|
192
|
-
- lib/treaty/request/
|
|
193
|
-
- lib/treaty/request/attribute/validator.rb
|
|
200
|
+
- lib/treaty/request/entity.rb
|
|
194
201
|
- lib/treaty/request/factory.rb
|
|
202
|
+
- lib/treaty/request/validator.rb
|
|
195
203
|
- lib/treaty/response/attribute/attribute.rb
|
|
196
204
|
- lib/treaty/response/attribute/builder.rb
|
|
197
|
-
- lib/treaty/response/
|
|
198
|
-
- lib/treaty/response/attribute/validator.rb
|
|
205
|
+
- lib/treaty/response/entity.rb
|
|
199
206
|
- lib/treaty/response/factory.rb
|
|
207
|
+
- lib/treaty/response/validator.rb
|
|
200
208
|
- lib/treaty/result.rb
|
|
201
209
|
- lib/treaty/strategy.rb
|
|
202
210
|
- lib/treaty/support/loader.rb
|
data/lib/treaty/info/builder.rb
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Treaty
|
|
4
|
-
module Info
|
|
5
|
-
class Builder
|
|
6
|
-
attr_reader :versions
|
|
7
|
-
|
|
8
|
-
def self.build(...)
|
|
9
|
-
new.build(...)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def build(collection_of_versions:)
|
|
13
|
-
build_all(
|
|
14
|
-
versions: collection_of_versions
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
self
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
def build_all(versions:)
|
|
23
|
-
build_versions_with(
|
|
24
|
-
collection: versions
|
|
25
|
-
)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
##########################################################################
|
|
29
|
-
|
|
30
|
-
def build_versions_with(collection:) # rubocop:disable Metrics/MethodLength
|
|
31
|
-
@versions = collection.map do |version|
|
|
32
|
-
gem_version = version.version.version
|
|
33
|
-
{
|
|
34
|
-
version: gem_version.version,
|
|
35
|
-
segments: gem_version.segments,
|
|
36
|
-
default: version.default_result,
|
|
37
|
-
summary: version.summary_text,
|
|
38
|
-
strategy: version.strategy_instance.code,
|
|
39
|
-
deprecated: version.deprecated_result,
|
|
40
|
-
executor: build_executor_with(version),
|
|
41
|
-
request: build_request_with(version),
|
|
42
|
-
response: build_response_with(version)
|
|
43
|
-
}
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
##########################################################################
|
|
48
|
-
|
|
49
|
-
def build_executor_with(version)
|
|
50
|
-
{
|
|
51
|
-
executor: version.executor.executor,
|
|
52
|
-
method: version.executor.method
|
|
53
|
-
}
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
##########################################################################
|
|
57
|
-
|
|
58
|
-
def build_request_with(version)
|
|
59
|
-
build_attributes_structure(version.request_factory)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def build_response_with(version)
|
|
63
|
-
response_factory = version.response_factory
|
|
64
|
-
{
|
|
65
|
-
status: response_factory.status
|
|
66
|
-
}.merge(build_attributes_structure(response_factory))
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
##########################################################################
|
|
70
|
-
|
|
71
|
-
def build_attributes_structure(factory)
|
|
72
|
-
{
|
|
73
|
-
attributes: build_attributes_hash(factory.collection_of_attributes)
|
|
74
|
-
}
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def build_attributes_hash(collection, current_level = 0)
|
|
78
|
-
# validate_nesting_level!(current_level)
|
|
79
|
-
|
|
80
|
-
collection.to_h do |attribute|
|
|
81
|
-
[
|
|
82
|
-
attribute.name,
|
|
83
|
-
{
|
|
84
|
-
type: attribute.type,
|
|
85
|
-
options: attribute.options,
|
|
86
|
-
attributes: build_nested_attributes(attribute, current_level)
|
|
87
|
-
}
|
|
88
|
-
]
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
def build_nested_attributes(attribute, current_level)
|
|
93
|
-
return {} unless attribute.nested?
|
|
94
|
-
|
|
95
|
-
build_attributes_hash(attribute.collection_of_attributes, current_level + 1)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# def validate_nesting_level!(level)
|
|
99
|
-
# return unless level > Treaty::Engine.config.treaty.attribute_nesting_level
|
|
100
|
-
#
|
|
101
|
-
# raise Treaty::Exceptions::NestedAttributes,
|
|
102
|
-
# I18n.t("treaty.attributes.errors.nesting_level_exceeded",
|
|
103
|
-
# level:,
|
|
104
|
-
# max_level: Treaty::Engine.config.treaty.attribute_nesting_level)
|
|
105
|
-
# end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
end
|