Module: RubyReactor::Dsl::Reactor::ClassMethods
Instance Method Summary
collapse
-
#async(async = true) ⇒ Object
-
#async? ⇒ Boolean
-
#call(inputs = {}) ⇒ Object
-
#compose(name, composed_reactor_class = nil, &block) ⇒ Object
-
#input(name, transform: nil, description: nil, validate: nil, optional: false, redact: false, &validation_block) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#input_validations ⇒ Object
-
#inputs ⇒ Object
-
#map(name, reactor_class = nil, &block) ⇒ Object
-
#middleware(middleware_class) ⇒ Object
-
#middlewares ⇒ Object
-
#retry_defaults(**kwargs) ⇒ Object
-
#return_step ⇒ Object
-
#returns(step_name) ⇒ Object
-
#run(inputs = {}) ⇒ Object
Entry point for running the reactor.
-
#step(name, impl = nil, &block) ⇒ Object
-
#steps ⇒ Object
-
#validate_inputs(inputs_hash) ⇒ Object
#build_validation_schema, #create_input_validator
#Failure, #Success, #element, #result, #value
Instance Method Details
#async(async = true) ⇒ Object
41
42
43
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 41
def async(async = true)
@async = async
end
|
#async? ⇒ Boolean
45
46
47
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 45
def async?
@async ||= false
end
|
#call(inputs = {}) ⇒ Object
145
146
147
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 145
def call(inputs = {})
run(inputs)
end
|
#compose(name, composed_reactor_class = nil, &block) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 89
def compose(name, composed_reactor_class = nil, &block)
builder = RubyReactor::Dsl::ComposeBuilder.new(name, composed_reactor_class, self, &block)
builder.instance_eval(&block) if block_given?
step_config = builder.build
steps[name] = step_config
step_config
end
|
rubocop:disable Metrics/ParameterLists
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 62
def input(name, transform: nil, description: nil, validate: nil, optional: false, redact: false,
&validation_block)
inputs[name] = {
transform: transform,
description: description,
optional: optional,
redact: redact
}
return unless validate || validation_block
validator = create_input_validator(validation_block || validate)
input_validations[name] = validator
end
|
37
38
39
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 37
def input_validations
@input_validations ||= {}
end
|
21
22
23
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 21
def inputs
@inputs ||= {}
end
|
#map(name, reactor_class = nil, &block) ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 99
def map(name, reactor_class = nil, &block)
builder = RubyReactor::Dsl::MapBuilder.new(name, reactor_class, self, &block)
builder.instance_eval(&block) if block_given?
step_config = builder.build
steps[name] = step_config
step_config
end
|
#middleware(middleware_class) ⇒ Object
113
114
115
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 113
def middleware(middleware_class)
middlewares << middleware_class
end
|
#middlewares ⇒ Object
33
34
35
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 33
def middlewares
@middlewares ||= []
end
|
#retry_defaults(**kwargs) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 49
def retry_defaults(**kwargs)
if kwargs.empty?
@retry_defaults ||= { max_attempts: 1, backoff: :exponential, base_delay: 1 }
else
@retry_defaults = {
max_attempts: kwargs[:max_attempts] || 1,
backoff: kwargs[:backoff] || :exponential,
base_delay: kwargs[:base_delay] || 1
}
end
end
|
#return_step ⇒ Object
29
30
31
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 29
def return_step
@return_step
end
|
#returns(step_name) ⇒ Object
109
110
111
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 109
def returns(step_name)
@return_step = step_name
end
|
#run(inputs = {}) ⇒ Object
Entry point for running the reactor
140
141
142
143
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 140
def run(inputs = {})
reactor = new
reactor.run(inputs)
end
|
#step(name, impl = nil, &block) ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 79
def step(name, impl = nil, &block)
builder = RubyReactor::Dsl::StepBuilder.new(name, impl, self)
builder.instance_eval(&block) if block_given?
step_config = builder.build
steps[name] = step_config
step_config
end
|
#steps ⇒ Object
25
26
27
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 25
def steps
@steps ||= {}
end
|
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# File 'lib/ruby_reactor/dsl/reactor.rb', line 117
def validate_inputs(inputs_hash)
errors = {}
input_validations.each do |input_name, validator|
next if inputs[input_name][:optional] && !inputs_hash.key?(input_name)
input_data = inputs_hash[input_name]
result = validator.call({ input_name => input_data })
errors.merge!(result.error.field_errors) if result.failure? && result.error.respond_to?(:field_errors)
end
if errors.empty?
RubyReactor.Success(inputs_hash)
else
error = RubyReactor::Error::InputValidationError.new(errors)
RubyReactor.Failure(error)
end
end
|