Class: Foobara::TransformedCommand
- Inherits:
-
Object
- Object
- Foobara::TransformedCommand
- Defined in:
- foobara-0.0.110/projects/command/src/transformed_command.rb
Overview
TODO: feels so strange that this doesn’t inherit from command TODO: move this to command connectors project
Class Attribute Summary collapse
-
.allowed_rule ⇒ Object
Returns the value of attribute allowed_rule.
-
.authenticator ⇒ Object
Returns the value of attribute authenticator.
-
.capture_unknown_error ⇒ Object
Returns the value of attribute capture_unknown_error.
-
.command_class ⇒ Object
Returns the value of attribute command_class.
-
.command_name ⇒ Object
Returns the value of attribute command_name.
-
.errors_transformers ⇒ Object
Returns the value of attribute errors_transformers.
-
.full_command_name ⇒ Object
Returns the value of attribute full_command_name.
-
.inputs_transformers ⇒ Object
Returns the value of attribute inputs_transformers.
-
.pre_commit_transformers ⇒ Object
Returns the value of attribute pre_commit_transformers.
-
.request_mutators ⇒ Object
Returns the value of attribute request_mutators.
-
.requires_authentication ⇒ Object
Returns the value of attribute requires_authentication.
-
.response_mutators ⇒ Object
Returns the value of attribute response_mutators.
-
.result_transformers ⇒ Object
Returns the value of attribute result_transformers.
-
.serializers ⇒ Object
Returns the value of attribute serializers.
Instance Attribute Summary collapse
-
#authenticated_user ⇒ Object
Returns the value of attribute authenticated_user.
-
#command ⇒ Object
Returns the value of attribute command.
-
#outcome ⇒ Object
Returns the value of attribute outcome.
-
#transformed_inputs ⇒ Object
Returns the value of attribute transformed_inputs.
-
#untransformed_inputs ⇒ Object
Returns the value of attribute untransformed_inputs.
Class Method Summary collapse
- .error_context_type_map ⇒ Object
- .foobara_manifest ⇒ Object
- .inputs_transformer ⇒ Object
- .inputs_type ⇒ Object
- .inputs_type_for_manifest ⇒ Object
- .inputs_types_depended_on ⇒ Object
- .mutate_request(request) ⇒ Object
- .possible_errors ⇒ Object
- .possible_errors_manifest ⇒ Object
- .request_mutator ⇒ Object
- .response_mutator ⇒ Object
- .result_transformer ⇒ Object
- .result_type ⇒ Object
- .result_type_for_manifest ⇒ Object
- .result_type_from_transformers(result_type, transformers) ⇒ Object
- .result_types_depended_on ⇒ Object
- .subclass(command_class, scoped_namespace:, full_command_name:, command_name:, inputs_transformers:, result_transformers:, errors_transformers:, pre_commit_transformers:, serializers:, response_mutators:, request_mutators:, allowed_rule:, requires_authentication:, authenticator:, suffix: nil, capture_unknown_error: false) ⇒ Object
-
.transformers_to_processors(transformers, target_type, direction: :from, declaration_data: self) ⇒ Object
TODO: this is pretty messy with smells.
- .types_depended_on ⇒ Object
Instance Method Summary collapse
- #apply_allowed_rule ⇒ Object
- #apply_pre_commit_transformers ⇒ Object
- #construct_command ⇒ Object
- #errors ⇒ Object
- #errors_transformer ⇒ Object
-
#initialize(untransformed_inputs = {}) ⇒ TransformedCommand
constructor
A new instance of TransformedCommand.
- #method_missing(method_name) ⇒ Object
- #mutate_response(response) ⇒ Object
-
#pre_commit_transformer ⇒ Object
TODO: memoize.
- #requires_authentication? ⇒ Boolean
- #respond_to_missing?(method_name, private = false) ⇒ Boolean
- #result ⇒ Object
- #run ⇒ Object
- #run_command ⇒ Object
-
#serialize_result(body) ⇒ Object
TODO: kill this.
-
#serializer ⇒ Object
TODO: let’s get this out of here…
- #transform_errors ⇒ Object
- #transform_inputs ⇒ Object
- #transform_outcome ⇒ Object
- #transform_result ⇒ Object
Constructor Details
#initialize(untransformed_inputs = {}) ⇒ TransformedCommand
Returns a new instance of TransformedCommand.
445 446 447 448 449 450 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 445 def initialize(untransformed_inputs = {}) self.untransformed_inputs = untransformed_inputs || {} transform_inputs construct_command end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
643 644 645 646 647 648 649 650 651 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 643 def method_missing(method_name, ...) if command.respond_to?(method_name) command.send(method_name, ...) else # :nocov: super # :nocov: end end |
Class Attribute Details
.allowed_rule ⇒ Object
Returns the value of attribute allowed_rule.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def allowed_rule @allowed_rule end |
.authenticator ⇒ Object
Returns the value of attribute authenticator.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def authenticator @authenticator end |
.capture_unknown_error ⇒ Object
Returns the value of attribute capture_unknown_error.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def capture_unknown_error @capture_unknown_error end |
.command_class ⇒ Object
Returns the value of attribute command_class.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def command_class @command_class end |
.command_name ⇒ Object
Returns the value of attribute command_name.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def command_name @command_name end |
.errors_transformers ⇒ Object
Returns the value of attribute errors_transformers.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def errors_transformers @errors_transformers end |
.full_command_name ⇒ Object
Returns the value of attribute full_command_name.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def full_command_name @full_command_name end |
.inputs_transformers ⇒ Object
Returns the value of attribute inputs_transformers.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def inputs_transformers @inputs_transformers end |
.pre_commit_transformers ⇒ Object
Returns the value of attribute pre_commit_transformers.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def pre_commit_transformers @pre_commit_transformers end |
.request_mutators ⇒ Object
Returns the value of attribute request_mutators.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def request_mutators @request_mutators end |
.requires_authentication ⇒ Object
Returns the value of attribute requires_authentication.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def requires_authentication @requires_authentication end |
.response_mutators ⇒ Object
Returns the value of attribute response_mutators.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def response_mutators @response_mutators end |
.result_transformers ⇒ Object
Returns the value of attribute result_transformers.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def result_transformers @result_transformers end |
.serializers ⇒ Object
Returns the value of attribute serializers.
6 7 8 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 6 def serializers @serializers end |
Instance Attribute Details
#authenticated_user ⇒ Object
Returns the value of attribute authenticated_user.
443 444 445 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 443 def authenticated_user @authenticated_user end |
#command ⇒ Object
Returns the value of attribute command.
443 444 445 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 443 def command @command end |
#outcome ⇒ Object
Returns the value of attribute outcome.
443 444 445 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 443 def outcome @outcome end |
#transformed_inputs ⇒ Object
Returns the value of attribute transformed_inputs.
443 444 445 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 443 def transformed_inputs @transformed_inputs end |
#untransformed_inputs ⇒ Object
Returns the value of attribute untransformed_inputs.
443 444 445 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 443 def untransformed_inputs @untransformed_inputs end |
Class Method Details
.error_context_type_map ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 144 def error_context_type_map @error_context_type_map ||= begin set = {} command_class.possible_errors.each do |possible_error| # For now, we get the input errors off the transformed inputs_type. # This way if an inputs transformer changes the path of an input, we don't wind up with the old path # in the errors. if possible_error.error_class < Foobara::RuntimeError set[possible_error.key.to_s] = possible_error end end command_class.manually_added_possible_input_errors.each do |possible_error| set[possible_error.key.to_s] = possible_error end inputs_type&.possible_errors&.each do |possible_error| set[possible_error.key.to_s] = possible_error end errors_transformers.each do |transformer| set = transformer.transform_error_context_type_map(self, set) end set end end |
.foobara_manifest ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 260 def to_include = TypeDeclarations. types = types_depended_on.select(&:registered?).map do |t| if to_include to_include << t end t. end.sort inputs_transformers = TypeDeclarations.with_manifest_context(remove_sensitive: false) do self.inputs_transformers.map(&:foobara_manifest) end result_transformers = self.result_transformers.map(&:foobara_manifest) errors_transformers = self.errors_transformers.map(&:foobara_manifest) pre_commit_transformers = self.pre_commit_transformers.map(&:foobara_manifest) serializers = self.serializers.map do |s| if s.respond_to?(:foobara_manifest) if to_include to_include << s end s. else { proc: s.to_s } end end response_mutators = self.response_mutators.map(&:foobara_manifest) request_mutators = TypeDeclarations.with_manifest_context(remove_sensitive: false) do self.request_mutators.map(&:foobara_manifest) end authenticator_manifest = if authenticator if authenticator.respond_to?(:foobara_manifest) # TODO: test this path # :nocov: authenticator. # :nocov: else true end end inputs_types_depended_on = TypeDeclarations.with_manifest_context(remove_sensitive: false) do self.inputs_types_depended_on.map(&:foobara_manifest_reference).sort end result_types_depended_on = self.result_types_depended_on.map(&:foobara_manifest_reference) result_types_depended_on = result_types_depended_on.sort # TODO: Do NOT defer to command_class.foobara_manifest because it might process types that # might not have an exposed command and might not need one due to transformers/mutators/remove_sensitive flag command_class..merge( Util.remove_blank( inputs_types_depended_on:, result_types_depended_on:, types_depended_on: types, inputs_type: TypeDeclarations.with_manifest_context(remove_sensitive: false) do inputs_type_for_manifest&.reference_or_declaration_data end, result_type: result_type_for_manifest&.reference_or_declaration_data, possible_errors: possible_errors_manifest, capture_unknown_error:, inputs_transformers:, result_transformers:, errors_transformers:, pre_commit_transformers:, serializers:, response_mutators:, request_mutators:, requires_authentication:, authenticator: authenticator_manifest ) ) end |
.inputs_transformer ⇒ Object
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 336 def inputs_transformer return @inputs_transformer if defined?(@inputs_transformer) if inputs_transformers.empty? @inputs_transformer = nil return end @inputs_transformer = begin transformers = transformers_to_processors(inputs_transformers, command_class.inputs_type, direction: :to) if transformers.size == 1 transformers.first else Value::Processor::Pipeline.new(processors: transformers) end end end |
.inputs_type ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 81 def inputs_type return @inputs_type if defined?(@inputs_type) @inputs_type = if inputs_transformer if inputs_transformer.is_a?(Value::Processor::Pipeline) inputs_transformer.processors.each do |transformer| if transformer.is_a?(TypeDeclarations::TypedTransformer) from_type = transformer.from_type if from_type @inputs_type = from_type return from_type end end end command_class.inputs_type else inputs_transformer.from_type || command_class.inputs_type end else command_class.inputs_type end end |
.inputs_type_for_manifest ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 132 def inputs_type_for_manifest return @inputs_type_for_manifest if defined?(@inputs_type_for_manifest) mutated_inputs_type = inputs_type request_mutators&.each do |mutator| mutated_inputs_type = mutator.instance.inputs_type_from(mutated_inputs_type) end @inputs_type_for_manifest = mutated_inputs_type end |
.inputs_types_depended_on ⇒ Object
191 192 193 194 195 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 191 def inputs_types_depended_on TypeDeclarations.with_manifest_context(remove_sensitive: false) do inputs_type_for_manifest&.types_depended_on || [] end end |
.mutate_request(request) ⇒ Object
394 395 396 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 394 def mutate_request(request) request_mutator&.process_value!(request) end |
.possible_errors ⇒ Object
173 174 175 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 173 def possible_errors @possible_errors ||= error_context_type_map.values end |
.possible_errors_manifest ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 177 def possible_errors_manifest errors_proc = -> do possible_errors.map do |possible_error| [possible_error.key.to_s, possible_error.] end.sort.to_h end if TypeDeclarations.manifest_context_set?(:remove_sensitive) errors_proc.call else TypeDeclarations.with_manifest_context(remove_sensitive: true, &errors_proc) end end |
.request_mutator ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 375 def request_mutator return @request_mutator if defined?(@request_mutator) if request_mutators.empty? @request_mutator = nil return end @request_mutator = begin transformers = transformers_to_processors(request_mutators, result_type, direction: :to) if transformers.size == 1 transformers.first else Value::Processor::Pipeline.new(processors: transformers) end end end |
.response_mutator ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 356 def response_mutator return @response_mutator if defined?(@response_mutator) if response_mutators.empty? @response_mutator = nil return end @response_mutator = begin transformers = transformers_to_processors(response_mutators, result_type, direction: :from) if transformers.size == 1 transformers.first else Value::Processor::Pipeline.new(processors: transformers) end end end |
.result_transformer ⇒ Object
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 398 def result_transformer return @result_transformer if defined?(@result_transformer) if result_transformers.empty? @result_transformer = nil return end @result_transformer = begin transformers = transformers_to_processors(result_transformers, command_class.result_type, direction: :from) if transformers.size == 1 transformers.first else Value::Processor::Pipeline.new(processors: transformers) end end end |
.result_type ⇒ Object
116 117 118 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 116 def result_type result_type_from_transformers(command_class.result_type, result_transformers) end |
.result_type_for_manifest ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 120 def result_type_for_manifest return @result_type_for_manifest if defined?(@result_type_for_manifest) mutated_result_type = result_type response_mutators&.reverse&.each do |mutator| mutated_result_type = mutator.instance.result_type_from(mutated_result_type) end @result_type_for_manifest = mutated_result_type end |
.result_type_from_transformers(result_type, transformers) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 105 def result_type_from_transformers(result_type, transformers) transformers.reverse.each do |transformer| if transformer.is_a?(Class) && transformer < TypeDeclarations::TypedTransformer new_type = transformer.to_type return new_type if new_type end end result_type end |
.result_types_depended_on ⇒ Object
197 198 199 200 201 202 203 204 205 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 197 def result_types_depended_on type_proc = -> { result_type_for_manifest&.types_depended_on || [] } if TypeDeclarations.manifest_context_set?(:remove_sensitive) type_proc.call else TypeDeclarations.with_manifest_context(remove_sensitive: true, &type_proc) end end |
.subclass(command_class, scoped_namespace:, full_command_name:, command_name:, inputs_transformers:, result_transformers:, errors_transformers:, pre_commit_transformers:, serializers:, response_mutators:, request_mutators:, allowed_rule:, requires_authentication:, authenticator:, suffix: nil, capture_unknown_error: false) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 25 def subclass( command_class, scoped_namespace:, full_command_name:, command_name:, inputs_transformers:, result_transformers:, errors_transformers:, pre_commit_transformers:, serializers:, response_mutators:, request_mutators:, allowed_rule:, requires_authentication:, authenticator:, suffix: nil, capture_unknown_error: false ) result_type = command_class.result_type if result_type&.has_sensitive_types? remover_class = Foobara::TypeDeclarations.sensitive_value_remover_class_for_type(result_type) remover = Namespace.use scoped_namespace do transformed_result_type = result_type_from_transformers(result_type, result_transformers) remover_class.new(from: transformed_result_type).tap do |r| r.scoped_path = ["SensitiveValueRemover", *transformed_result_type.scoped_full_path] end end result_transformers = [*result_transformers, remover] end Class.new(self).tap do |klass| klass.command_class = command_class klass.command_name = command_name klass.full_command_name = full_command_name klass.capture_unknown_error = capture_unknown_error klass.inputs_transformers = Util.array(inputs_transformers) klass.result_transformers = Util.array(result_transformers) klass.errors_transformers = Util.array(errors_transformers) klass.pre_commit_transformers = Util.array(pre_commit_transformers) klass.serializers = Util.array(serializers) klass.response_mutators = Util.array(response_mutators) klass.request_mutators = Util.array(request_mutators) klass.allowed_rule = allowed_rule klass.requires_authentication = requires_authentication klass.authenticator = authenticator end end |
.transformers_to_processors(transformers, target_type, direction: :from, declaration_data: self) ⇒ Object
TODO: this is pretty messy with smells.
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 418 def transformers_to_processors(transformers, target_type, direction: :from, declaration_data: self) transformers.map do |transformer| if transformer.is_a?(Class) if transformer < TypeDeclarations::TypedTransformer transformer.new(direction => target_type).tap do |tx| new_type = direction == :from ? tx.to_type : tx.from_type target_type = new_type if new_type end else # TODO: perhaps pass in the command connector as the parent declaration data? transformer.new_with_agnostic_args(declaration_data:) end elsif transformer.is_a?(Value::Processor) transformer elsif transformer.respond_to?(:call) Value::Transformer.create(transform: transformer) else # :nocov: raise "Not sure how to apply #{inputs_transformer}" # :nocov: end end end |
.types_depended_on ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 207 def types_depended_on # Seems to be not necessary? # types = command_class.types_depended_on types = Set.new # TODO: memoize this # TODO: this should not delegate to command since transformers are in play type = inputs_type if type if type.registered? # TODO: if we ever change from attributes-only inputs type # then this will be handy # :nocov: types |= [type] # :nocov: end types |= type.types_depended_on end types_proc = proc do type = result_type if type if type.registered? # TODO: if we ever change from attributes-only inputs type # then this will be handy # :nocov: types |= [type] # :nocov: end types |= type.types_depended_on end possible_errors.each do |possible_error| error_class = possible_error.error_class types |= error_class.types_depended_on end types end if TypeDeclarations.manifest_context_set?(:remove_sensitive) types_proc.call else TypeDeclarations.with_manifest_context(remove_sensitive: true, &types_proc) end end |
Instance Method Details
#apply_allowed_rule ⇒ Object
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 555 def apply_allowed_rule rule = allowed_rule if rule command.after_load_records do |command:, **| is_allowed = instance_exec(&rule) unless is_allowed explanation = allowed_rule.explanation if explanation.is_a?(Proc) explanation = instance_eval(&explanation) end if explanation.nil? source = if allowed_rule.block.respond_to?("source") && defined?(MethodSource) begin # This only works when pry is loaded allowed_rule.block.source rescue MethodSource::SourceNotFoundError # This path is hit if the way the source code is extracted # doesn't result in valid Ruby, for example, as part of a hash such as: # allowed_rule: -> () { whatever?(something) }, end end source ||= allowed_rule.block.source_location.join(":") explanation = source || "No explanation." end error = CommandConnector::NotAllowedError.for(rule_symbol: rule.symbol, explanation:) self.outcome = Outcome.error(error) command.state_machine.error! command.halt! end end end end |
#apply_pre_commit_transformers ⇒ Object
595 596 597 598 599 600 601 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 595 def apply_pre_commit_transformers if pre_commit_transformer command.before_commit_transaction do |**| pre_commit_transformer.process_value!(self) end end end |
#construct_command ⇒ Object
551 552 553 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 551 def construct_command self.command = command_class.new(transformed_inputs) end |
#errors ⇒ Object
621 622 623 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 621 def errors outcome.errors end |
#errors_transformer ⇒ Object
521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 521 def errors_transformer return nil if errors_transformers.empty? transformers = self.class.transformers_to_processors(errors_transformers, nil, direction: :from, declaration_data: self) if transformers.size == 1 transformers.first else Value::Processor::Pipeline.new(processors: transformers) end end |
#mutate_response(response) ⇒ Object
495 496 497 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 495 def mutate_response(response) self.class.response_mutator&.process_value!(response) end |
#pre_commit_transformer ⇒ Object
TODO: memoize
535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 535 def pre_commit_transformer return nil if pre_commit_transformers.empty? transformers = self.class.transformers_to_processors( pre_commit_transformers, nil, declaration_data: self ) if transformers.size == 1 transformers.first else Value::Processor::Pipeline.new(processors: transformers) end end |
#requires_authentication? ⇒ Boolean
477 478 479 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 477 def requires_authentication? !!requires_authentication end |
#respond_to_missing?(method_name, private = false) ⇒ Boolean
653 654 655 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 653 def respond_to_missing?(method_name, private = false) command.respond_to?(method_name, private) || super end |
#result ⇒ Object
617 618 619 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 617 def result outcome.result end |
#run ⇒ Object
467 468 469 470 471 472 473 474 475 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 467 def run apply_allowed_rule apply_pre_commit_transformers run_command # TODO: do this within the transaction!!! transform_outcome outcome end |
#run_command ⇒ Object
603 604 605 606 607 608 609 610 611 612 613 614 615 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 603 def run_command outcome = command.run self.outcome = outcome if outcome rescue => e if capture_unknown_error # TODO: move to superclass? self.outcome = Outcome.error(CommandConnector::UnknownError.for(e)) else # :nocov: raise # :nocov: end end |
#serialize_result(body) ⇒ Object
TODO: kill this
635 636 637 638 639 640 641 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 635 def serialize_result(body) if serializer serializer.process_value!(body) else body end end |
#serializer ⇒ Object
TODO: let’s get this out of here… we might want to have different serializers for different command instances of the same class. but currently serializers is set on the class. Since this class should not be concerned with serialization, we should just try to relocate this to the Request which could delegate to the registry for defaults.
509 510 511 512 513 514 515 516 517 518 519 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 509 def serializer return nil if serializers.empty? transformers = self.class.transformers_to_processors(serializers, nil, declaration_data: self) if transformers.size == 1 transformers.first else Value::Processor::Pipeline.new(processors: transformers) end end |
#transform_errors ⇒ Object
499 500 501 502 503 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 499 def transform_errors if errors_transformer self.outcome = Outcome.errors(errors_transformer.process_value!(errors)) end end |
#transform_inputs ⇒ Object
481 482 483 484 485 486 487 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 481 def transform_inputs self.transformed_inputs = if self.class.inputs_transformer self.class.inputs_transformer.process_value!(untransformed_inputs) else untransformed_inputs end end |
#transform_outcome ⇒ Object
625 626 627 628 629 630 631 632 |
# File 'foobara-0.0.110/projects/command/src/transformed_command.rb', line 625 def transform_outcome if outcome.success? # can we do this while still in the transaction of the command??? transform_result else transform_errors end end |