trailblazer-endpoint 0.0.2 → 0.0.3
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/CHANGES.md +5 -0
- data/lib/trailblazer/endpoint.rb +5 -2
- data/lib/trailblazer/endpoint/controller.rb +7 -0
- data/lib/trailblazer/endpoint/dsl.rb +26 -0
- data/lib/trailblazer/endpoint/options.rb +145 -0
- data/lib/trailblazer/endpoint/version.rb +1 -1
- data/test/config_test.rb +103 -0
- data/test/docs/controller_test.rb +195 -60
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1f9924623a3e82ffce7398379c645bc0d6502e66d1d827231fb12b108e40978
|
4
|
+
data.tar.gz: 8a2f575d512c830e3ea29d2cff65ac8aed6f86cf75364a516102664c2928c928
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b817a46e644b31127385bcac23a5ec122a5bdd4cb9fd3a425f4d92a1be3d4e2fb35a70f28d13850902116a892bd445df3e4c795b895557bdf085de7505f2c71
|
7
|
+
data.tar.gz: fc0f421d1bcfa2c3ccf08f599ffa503c7d0cf7b8a64a387d88270ad68466e00f2cd79654b4a71ead8bf4425a231272b6ef6089dd5e5416d56f4961c7cba0f97d
|
data/CHANGES.md
CHANGED
data/lib/trailblazer/endpoint.rb
CHANGED
@@ -76,7 +76,7 @@ module Trailblazer
|
|
76
76
|
end
|
77
77
|
|
78
78
|
#@ For WORKFLOW and operations. not sure this method will stay here.
|
79
|
-
def self.arguments_for(domain_ctx:, flow_options:, circuit_options: {}, **
|
79
|
+
def self.arguments_for(domain_ctx:, flow_options:, circuit_options: {}, **endpoint_options)
|
80
80
|
domain_ctx = Trailblazer::Context::IndifferentAccess.build(domain_ctx, {}, [domain_ctx, flow_options], circuit_options)
|
81
81
|
|
82
82
|
[
|
@@ -89,7 +89,7 @@ module Trailblazer
|
|
89
89
|
# encrypted_resume_data: encrypted_resume_data,
|
90
90
|
|
91
91
|
# cipher_key: cipher_key,
|
92
|
-
**
|
92
|
+
**endpoint_options,
|
93
93
|
},
|
94
94
|
flow_options
|
95
95
|
],
|
@@ -125,3 +125,6 @@ end
|
|
125
125
|
|
126
126
|
require "trailblazer/endpoint/protocol"
|
127
127
|
require "trailblazer/endpoint/adapter"
|
128
|
+
require "trailblazer/endpoint/dsl"
|
129
|
+
require "trailblazer/endpoint/controller"
|
130
|
+
require "trailblazer/endpoint/options"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Trailblazer
|
2
|
+
class Endpoint
|
3
|
+
module DSL
|
4
|
+
# Run before the endpoint is invoked. This collects the blocks from the controller.
|
5
|
+
class Runtime < Struct.new(:args, :success_block, :failure_block, :protocol_failure_block)
|
6
|
+
|
7
|
+
def failure(&block)
|
8
|
+
self.failure_block = block
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
alias_method :Or, :failure
|
13
|
+
|
14
|
+
def protocol_failure(&block)
|
15
|
+
self.protocol_failure_block = block
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
# #call
|
20
|
+
def to_args
|
21
|
+
return args, {success_block: success_block, failure_block: failure_block, protocol_failure_block: protocol_failure_block}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# TODO
|
2
|
+
module Trailblazer
|
3
|
+
class Endpoint
|
4
|
+
def self.Normalizer(target:, options:)
|
5
|
+
normalizer = Class.new(Trailblazer::Activity::Railway) do
|
6
|
+
# inject an empty {} for all options.
|
7
|
+
# options.collect do |(method_name => option)|
|
8
|
+
# step Normalizer.DefaultToEmptyHash(config_name), id: :"default_#{config_name}"
|
9
|
+
# end
|
10
|
+
end
|
11
|
+
|
12
|
+
Normalizer::State.new(normalizer, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.Normalizer___(options, base_class: Trailblazer::Activity::Path)
|
16
|
+
normalizer = Class.new(base_class) do
|
17
|
+
# inject an empty {} for all options.
|
18
|
+
# options.collect do |(method_name => option)|
|
19
|
+
# step Normalizer.DefaultToEmptyHash(config_name), id: :"default_#{config_name}"
|
20
|
+
# end
|
21
|
+
end
|
22
|
+
|
23
|
+
Normalizer.add(normalizer, nil, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
module Options
|
27
|
+
module DSL
|
28
|
+
def directive(directive_name, *callables, inherit: superclass)
|
29
|
+
options = {}
|
30
|
+
|
31
|
+
if inherit
|
32
|
+
options[:base_class] = instance_variable_get(:@normalizers)[directive_name] || Trailblazer::Activity::Path # FIXME
|
33
|
+
end
|
34
|
+
|
35
|
+
@normalizers[directive_name] = Trailblazer::Endpoint::Normalizer.Options(directive_name, *callables, **options) # DISCUSS: allow multiple calls?
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.extended(extended) # TODO: let's hope this is only called once per hierachy :)
|
39
|
+
extended.instance_variable_set(:@normalizers, {})
|
40
|
+
end
|
41
|
+
|
42
|
+
module Inherit
|
43
|
+
def inherited(subclass)
|
44
|
+
super
|
45
|
+
|
46
|
+
subclass.instance_variable_set(:@normalizers, @normalizers.dup)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def options_for(directive_name, runtime_options)
|
52
|
+
normalizer = @normalizers[directive_name]
|
53
|
+
|
54
|
+
ctx = Trailblazer::Context::IndifferentAccess.build(runtime_options, {}, [{}, {}], {}) # FIXME: easier {::build}, please!
|
55
|
+
|
56
|
+
signal, (ctx, ) = Trailblazer::Developer.wtf?(normalizer, [ctx])
|
57
|
+
|
58
|
+
_, options = ctx.decompose
|
59
|
+
options
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module Normalizer
|
64
|
+
def self.Options(directive_name, *callables, base_class: Trailblazer::Activity::Path)
|
65
|
+
normalizer = Class.new(base_class) do
|
66
|
+
end
|
67
|
+
|
68
|
+
Normalizer.add(normalizer, directive_name, callables)
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.DefaultToEmptyHash(config_name)
|
72
|
+
-> (ctx, **) { ctx[config_name] ||= {} }
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.add_normalizer!(target, normalizer, config)
|
76
|
+
normalizer = Normalizer.add(normalizer, target, config) # add configure steps for {subclass} to the _new_ normalizer.
|
77
|
+
target.instance_variable_set(:@normalizer, normalizer)
|
78
|
+
target.instance_variable_set(:@config, config)
|
79
|
+
end
|
80
|
+
|
81
|
+
class State < Module
|
82
|
+
def initialize(normalizer, config)
|
83
|
+
@normalizer = normalizer
|
84
|
+
@config = config
|
85
|
+
end
|
86
|
+
|
87
|
+
# called once when extended in {ApplicationController}.
|
88
|
+
def extended(extended)
|
89
|
+
super
|
90
|
+
|
91
|
+
extended.extend(Inherited)
|
92
|
+
Normalizer.add_normalizer!(extended, @normalizer, @config)
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
module Inherited
|
97
|
+
def inherited(subclass)
|
98
|
+
super
|
99
|
+
|
100
|
+
Normalizer.add_normalizer!(subclass, @normalizer, @config)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.add(normalizer, directive_name, options)
|
105
|
+
Class.new(normalizer) do
|
106
|
+
options.collect do |callable|
|
107
|
+
step task: Normalizer.CallDirective(callable, directive_name), id: "#{directive_name}=>#{callable}"
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.CallDirectiveMethod(target, config_name)
|
113
|
+
->((ctx, flow_options), *) {
|
114
|
+
config = target.send(config_name, ctx, **ctx) # e.g. ApplicationController.options_for_endpoint
|
115
|
+
|
116
|
+
ctx[config_name] = ctx[config_name].merge(config)
|
117
|
+
|
118
|
+
return Trailblazer::Activity::Right, [ctx, flow_options]
|
119
|
+
}
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.CallDirective(callable, option_name)
|
123
|
+
->((ctx, flow_options), *) {
|
124
|
+
config = callable.(ctx, **ctx) # e.g. ApplicationController.options_for_endpoint
|
125
|
+
|
126
|
+
# ctx[option_name] = ctx[option_name].merge(config)
|
127
|
+
config.each do |k, v|
|
128
|
+
ctx[k] = v
|
129
|
+
end
|
130
|
+
|
131
|
+
return Trailblazer::Activity::Right, [ctx, flow_options]
|
132
|
+
}
|
133
|
+
end
|
134
|
+
end # Normalizer
|
135
|
+
|
136
|
+
module Controller
|
137
|
+
def self.extended(extended)
|
138
|
+
extended.extend Trailblazer::Endpoint::Options::DSL
|
139
|
+
extended.extend Trailblazer::Endpoint::Options::DSL::Inherit
|
140
|
+
extended.extend Trailblazer::Endpoint::Options
|
141
|
+
end
|
142
|
+
end # Controller
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
data/test/config_test.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
require "trailblazer/endpoint/options"
|
4
|
+
|
5
|
+
class ConfigTest < Minitest::Spec
|
6
|
+
Controller = Struct.new(:params)
|
7
|
+
|
8
|
+
it "what" do
|
9
|
+
ApplicationController.options_for(:options_for_endpoint, {}).inspect.must_equal %{{:find_process_model=>true, :request=>true}}
|
10
|
+
|
11
|
+
# inherits endpoint options from ApplicationController
|
12
|
+
ApeController.options_for(:options_for_endpoint, {}).inspect.must_equal %{{:find_process_model=>true, :request=>true}}
|
13
|
+
# defines its own domain options, none in ApplicationController
|
14
|
+
ApeController.options_for(:options_for_domain_ctx, {}).inspect.must_equal %{{:current_user=>\"Yo\"}}
|
15
|
+
|
16
|
+
# 3-rd level, inherit everything from 2-nd level
|
17
|
+
ApeBabeController.options_for(:options_for_endpoint, {}).inspect.must_equal %{{:find_process_model=>true, :request=>true}}
|
18
|
+
ApeBabeController.options_for(:options_for_domain_ctx, {}).inspect.must_equal %{{:current_user=>\"Yo\"}}
|
19
|
+
|
20
|
+
BoringController.options_for(:options_for_endpoint, {}).inspect.must_equal %{{:find_process_model=>true, :request=>true, :xml=>"<XML"}}
|
21
|
+
BoringController.options_for(:options_for_domain_ctx, {}).inspect.must_equal %{{:policy=>\"Ehm\"}}
|
22
|
+
|
23
|
+
OverridingController.options_for(:options_for_domain_ctx, {}).inspect.must_equal %{{:redis=>\"Arrr\"}}
|
24
|
+
end
|
25
|
+
|
26
|
+
class ApplicationController
|
27
|
+
def self.options_for_endpoint(ctx, **)
|
28
|
+
{
|
29
|
+
find_process_model: true,
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.request_options(ctx, **)
|
34
|
+
{
|
35
|
+
request: true,
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
extend Trailblazer::Endpoint::Controller
|
40
|
+
directive :options_for_endpoint, method(:options_for_endpoint), method(:request_options)
|
41
|
+
end
|
42
|
+
|
43
|
+
class ApeController < ApplicationController
|
44
|
+
def self.options_for_domain_ctx(ctx, **)
|
45
|
+
{
|
46
|
+
current_user: "Yo",
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
directive :options_for_domain_ctx, method(:options_for_domain_ctx)
|
51
|
+
end
|
52
|
+
|
53
|
+
class ApeBabeController < ApeController
|
54
|
+
# def self.options_for_domain_ctx(ctx, **)
|
55
|
+
# {policy: "Ehm"}
|
56
|
+
# end
|
57
|
+
|
58
|
+
# directive :options_for_domain_ctx, method(:options_for_domain_ctx)
|
59
|
+
end
|
60
|
+
|
61
|
+
class BoringController < ApplicationController
|
62
|
+
def self.options_for_domain_ctx(ctx, **) {policy: "Ehm",} end
|
63
|
+
def self.options_for_endpoint(ctx, **) {xml: "<XML",} end
|
64
|
+
|
65
|
+
directive :options_for_endpoint, method(:options_for_endpoint) #, inherit: ApplicationController
|
66
|
+
directive :options_for_domain_ctx, method(:options_for_domain_ctx)
|
67
|
+
end
|
68
|
+
|
69
|
+
class OverridingController < BoringController
|
70
|
+
def self.options_for_domain_ctx(ctx, **)
|
71
|
+
{
|
72
|
+
redis: "Arrr",
|
73
|
+
}
|
74
|
+
end
|
75
|
+
directive :options_for_domain_ctx, method(:options_for_domain_ctx), inherit: false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class RuntimeOptionsTest < Minitest::Spec
|
80
|
+
class ApplicationController
|
81
|
+
def self.options_for_endpoint(ctx, controller:, **)
|
82
|
+
{
|
83
|
+
option: true,
|
84
|
+
params: controller[:params],
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
# You can access variables set prior to this options directive.
|
89
|
+
def self.request_options(ctx, controller:, params:, **)
|
90
|
+
{
|
91
|
+
my_params: params.inspect,
|
92
|
+
option: nil,
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
extend Trailblazer::Endpoint::Controller
|
97
|
+
directive :options_for_endpoint, method(:options_for_endpoint), method(:request_options)
|
98
|
+
end
|
99
|
+
|
100
|
+
it do
|
101
|
+
ApplicationController.options_for(:options_for_endpoint, controller: {params: {id: 1}}).inspect.must_equal %{{:option=>nil, :params=>{:id=>1}, :my_params=>\"{:id=>1}\"}}
|
102
|
+
end
|
103
|
+
end
|
@@ -1,92 +1,227 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
|
3
3
|
class DocsControllerTest < Minitest::Spec
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
|
5
|
+
class ApplicationController
|
6
|
+
def self.options_for_endpoint(ctx, **)
|
7
|
+
{
|
8
|
+
find_process_model: true,
|
9
|
+
}
|
8
10
|
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
12
|
+
def self.request_options(ctx, **)
|
13
|
+
{
|
14
|
+
request: true,
|
15
|
+
}
|
16
|
+
end
|
13
17
|
|
18
|
+
extend Trailblazer::Endpoint::Controller
|
19
|
+
directive :options_for_endpoint, method(:options_for_endpoint), method(:request_options)
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@endpoint = endpoint
|
19
|
-
@seq = []
|
21
|
+
def process(action_name, params:)
|
22
|
+
@params = params
|
23
|
+
send(action_name)
|
20
24
|
end
|
21
25
|
|
22
|
-
def
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
return
|
27
|
-
end
|
26
|
+
def render(text)
|
27
|
+
@render = text
|
28
|
+
end
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
31
|
+
class ApeController < ApplicationController
|
32
|
+
def self.options_for_domain_ctx(ctx, **)
|
33
|
+
{
|
34
|
+
current_user: "Yo",
|
35
|
+
}
|
32
36
|
end
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
directive :options_for_domain_ctx, method(:options_for_domain_ctx)
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
class HtmlController < ApplicationController
|
43
|
+
private def endpoint_for(*)
|
44
|
+
protocol = Class.new(Trailblazer::Endpoint::Protocol) do
|
45
|
+
include T.def_steps(:authenticate, :policy)
|
46
|
+
end
|
47
|
+
|
48
|
+
endpoint =
|
49
|
+
Trailblazer::Endpoint.build(
|
50
|
+
domain_activity: Minitest::Spec.new(nil).activity, # FIXME
|
51
|
+
protocol: protocol,
|
52
|
+
adapter: Trailblazer::Endpoint::Adapter::Web,
|
53
|
+
scope_domain_ctx: false,
|
54
|
+
|
55
|
+
) do
|
56
|
+
{Output(:not_found) => Track(:not_found)}
|
57
|
+
end
|
37
58
|
end
|
38
59
|
|
39
|
-
private def
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
60
|
+
private def advance_endpoint(options, &block)
|
61
|
+
endpoint = endpoint_for(options)
|
62
|
+
|
63
|
+
ctx = Trailblazer::Endpoint.advance_from_controller(
|
64
|
+
|
65
|
+
endpoint,
|
45
66
|
|
46
|
-
|
47
|
-
|
48
|
-
|
67
|
+
# retrieve/compute options_for_domain_ctx and options_for_endpoint
|
68
|
+
|
69
|
+
domain_ctx: {seq: seq=[], current_user: "Yo", **@params},
|
49
70
|
flow_options: {},
|
50
71
|
|
51
|
-
**
|
72
|
+
**options,
|
52
73
|
|
53
|
-
|
54
|
-
|
74
|
+
seq: seq,
|
75
|
+
current_user: "Yo",
|
76
|
+
**@params,
|
55
77
|
)
|
56
78
|
end
|
57
|
-
end
|
58
79
|
|
59
|
-
|
60
|
-
|
61
|
-
|
80
|
+
private def _endpoint(action, params: {}, &block)
|
81
|
+
success_block = ->(ctx, seq:, **) { render seq << :success_block }
|
82
|
+
failure_block = ->(ctx, seq:, **) { render seq << :failure_block }
|
83
|
+
protocol_failure_block = ->(ctx, seq:, **) { render seq << :protocol_failure_block }
|
84
|
+
|
85
|
+
dsl = Trailblazer::Endpoint::DSL::Runtime.new({action: action, params: params}, block || success_block, failure_block, protocol_failure_block) # provides #Or etc, is returned to {Controller#call}
|
62
86
|
end
|
63
87
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
adapter: Trailblazer::Endpoint::Adapter::Web,
|
69
|
-
scope_domain_ctx: false,
|
88
|
+
# all standard routes are user-defined
|
89
|
+
def view
|
90
|
+
_endpoint "view?" do |ctx, seq:, **|
|
91
|
+
render "success" + ctx[:current_user] + seq.inspect
|
70
92
|
|
71
|
-
|
72
|
-
|
93
|
+
end.failure do |ctx, seq:, **|
|
94
|
+
render "failure" + ctx[:current_user] + seq.inspect
|
95
|
+
|
96
|
+
end.protocol_failure do |ctx, seq:, **|
|
97
|
+
render "protocol_failure" + ctx[:current_user] + seq.inspect
|
98
|
+
end
|
73
99
|
end
|
74
100
|
|
75
|
-
|
76
|
-
|
77
|
-
|
101
|
+
# standard use-case: only success
|
102
|
+
def show
|
103
|
+
_endpoint "view?" do |ctx, seq:, **|
|
104
|
+
render "success" + ctx[:current_user] + seq.inspect
|
105
|
+
end
|
106
|
+
end
|
78
107
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
108
|
+
# standard use case: {success} and {failure}
|
109
|
+
def update
|
110
|
+
_endpoint "view?" do |ctx, seq:, **|
|
111
|
+
render "success" + ctx[:current_user] + seq.inspect
|
112
|
+
end.Or do |ctx, seq:, **|
|
113
|
+
render "Fail!" + ctx[:current_user] + seq.inspect
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def process(*)
|
118
|
+
dsl = super
|
119
|
+
|
120
|
+
options, block_options = dsl.to_args
|
121
|
+
|
122
|
+
advance_endpoint(**options, **block_options)
|
123
|
+
|
124
|
+
@render
|
125
|
+
end
|
126
|
+
|
127
|
+
end # HtmlController
|
83
128
|
|
84
129
|
it "what" do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
130
|
+
# success
|
131
|
+
controller = HtmlController.new
|
132
|
+
controller.process(:view, params: {}).must_equal %{successYo[:authenticate, :policy, :model, :validate]}
|
133
|
+
|
134
|
+
# failure
|
135
|
+
controller = HtmlController.new
|
136
|
+
controller.process(:view, params: {validate: false}).must_equal %{failureYo[:authenticate, :policy, :model, :validate]}
|
137
|
+
|
138
|
+
# protocol_failure
|
139
|
+
controller = HtmlController.new
|
140
|
+
controller.process(:view, params: {authenticate: false}).must_equal %{protocol_failureYo[:authenticate]}
|
141
|
+
end
|
142
|
+
|
143
|
+
it "only success_block is user-defined" do
|
144
|
+
# success
|
145
|
+
controller = HtmlController.new
|
146
|
+
controller.process(:show, params: {}).must_equal %{successYo[:authenticate, :policy, :model, :validate]}
|
147
|
+
|
148
|
+
# failure
|
149
|
+
controller = HtmlController.new
|
150
|
+
# from controller-default
|
151
|
+
controller.process(:show, params: {validate: false}).must_equal [:authenticate, :policy, :model, :validate, :failure_block]
|
152
|
+
|
153
|
+
# protocol_failure
|
154
|
+
controller = HtmlController.new
|
155
|
+
# from controller-default
|
156
|
+
controller.process(:show, params: {authenticate: false}).must_equal [:authenticate, :protocol_failure_block]
|
157
|
+
end
|
158
|
+
|
159
|
+
it "success/Or" do
|
160
|
+
# success
|
161
|
+
controller = HtmlController.new
|
162
|
+
controller.process(:update, params: {}).must_equal %{successYo[:authenticate, :policy, :model, :validate]}
|
163
|
+
|
164
|
+
# failure
|
165
|
+
controller = HtmlController.new
|
166
|
+
# from controller-default
|
167
|
+
controller.process(:update, params: {validate: false}).must_equal %{Fail!Yo[:authenticate, :policy, :model, :validate]}
|
168
|
+
|
169
|
+
# protocol_failure
|
170
|
+
controller = HtmlController.new
|
171
|
+
# from controller-default
|
172
|
+
controller.process(:update, params: {authenticate: false}).must_equal [:authenticate, :protocol_failure_block]
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
class ControllerOptionsTest < Minitest::Spec
|
177
|
+
class Controller
|
178
|
+
include Trailblazer::Endpoint::Controller
|
179
|
+
|
180
|
+
def view
|
181
|
+
endpoint "view?"
|
182
|
+
end
|
183
|
+
|
184
|
+
# we add {:options_for_domain_ctx} manually
|
185
|
+
def download
|
186
|
+
endpoint "download?", params: {id: params[:other_id]}, redis: "Redis"
|
187
|
+
end
|
188
|
+
|
189
|
+
# override some settings from {endpoint_options}:
|
190
|
+
def new
|
191
|
+
endpoint "new?", find_process_model: false
|
90
192
|
end
|
91
193
|
end
|
194
|
+
|
195
|
+
class ControllerThatDoesntInherit
|
196
|
+
include Trailblazer::Endpoint::Controller
|
197
|
+
|
198
|
+
def options_for_domain_ctx
|
199
|
+
{
|
200
|
+
params: params
|
201
|
+
}
|
202
|
+
end
|
203
|
+
|
204
|
+
def options_for_endpoint
|
205
|
+
|
206
|
+
end
|
207
|
+
|
208
|
+
def view
|
209
|
+
endpoint "view?"
|
210
|
+
end
|
211
|
+
|
212
|
+
# we add {:options_for_domain_ctx} manually
|
213
|
+
def download
|
214
|
+
endpoint "download?", params: {id: params[:other_id]}, redis: "Redis"
|
215
|
+
end
|
216
|
+
|
217
|
+
# override some settings from {endpoint_options}:
|
218
|
+
def new
|
219
|
+
endpoint "new?", find_process_model: false
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
it "allows to get options without a bloody controller" do
|
224
|
+
MemoController.bla(params: params)
|
225
|
+
end
|
92
226
|
end
|
227
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trailblazer-endpoint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Sutterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trailblazer-activity-dsl-linear
|
@@ -102,6 +102,9 @@ files:
|
|
102
102
|
- lib/trailblazer/endpoint.rb
|
103
103
|
- lib/trailblazer/endpoint/adapter.rb
|
104
104
|
- lib/trailblazer/endpoint/builder.rb
|
105
|
+
- lib/trailblazer/endpoint/controller.rb
|
106
|
+
- lib/trailblazer/endpoint/dsl.rb
|
107
|
+
- lib/trailblazer/endpoint/options.rb
|
105
108
|
- lib/trailblazer/endpoint/protocol.rb
|
106
109
|
- lib/trailblazer/endpoint/rails.rb
|
107
110
|
- lib/trailblazer/endpoint/version.rb
|
@@ -109,6 +112,7 @@ files:
|
|
109
112
|
- test/adapter/representable_test.rb
|
110
113
|
- test/adapter/web_test.rb
|
111
114
|
- test/benchmark/skill_resolver_benchmark.rb
|
115
|
+
- test/config_test.rb
|
112
116
|
- test/docs/controller_test.rb
|
113
117
|
- test/docs/endpoint_test.rb
|
114
118
|
- test/endpoint_test.rb
|
@@ -177,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
181
|
version: '0'
|
178
182
|
requirements: []
|
179
183
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.7.
|
184
|
+
rubygems_version: 2.7.6
|
181
185
|
signing_key:
|
182
186
|
specification_version: 4
|
183
187
|
summary: Endpoints handle authentication, policies, run your domain operation and
|
@@ -187,6 +191,7 @@ test_files:
|
|
187
191
|
- test/adapter/representable_test.rb
|
188
192
|
- test/adapter/web_test.rb
|
189
193
|
- test/benchmark/skill_resolver_benchmark.rb
|
194
|
+
- test/config_test.rb
|
190
195
|
- test/docs/controller_test.rb
|
191
196
|
- test/docs/endpoint_test.rb
|
192
197
|
- test/endpoint_test.rb
|