Class: Foobara::CommandConnector::Request
- Inherits:
-
Object
- Object
- Foobara::CommandConnector::Request
- Includes:
- NestedTransactionable, TruncatedInspect
- Defined in:
- foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb
Direct Known Subclasses
Foobara::CommandConnectors::Http::Request, Foobara::CommandConnectors::ShCliConnector::Request, McpConnector::JsonrpcRequest
Constant Summary
Constants included from TruncatedInspect
Instance Attribute Summary collapse
-
#action ⇒ Object
TODO: this feels like a smell of some sort…
-
#authenticated_credential ⇒ Object
TODO: this feels like a smell of some sort…
-
#authenticated_user ⇒ Object
TODO: this feels like a smell of some sort…
-
#command ⇒ Object
TODO: this feels like a smell of some sort…
-
#command_class ⇒ Object
TODO: this feels like a smell of some sort…
-
#command_connector ⇒ Object
TODO: this feels like a smell of some sort…
-
#error ⇒ Object
TODO: this feels like a smell of some sort…
-
#full_command_name ⇒ Object
TODO: this feels like a smell of some sort…
-
#inputs ⇒ Object
TODO: this feels like a smell of some sort…
-
#response ⇒ Object
TODO: this feels like a smell of some sort…
-
#serializers ⇒ Object
TODO: this feels like a smell of some sort…
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authenticator ⇒ Object
- #error_collection ⇒ Object
-
#initialize(**opts) ⇒ Request
constructor
A new instance of Request.
- #mutate_request ⇒ Object
- #outcome ⇒ Object
- #relevant_entity_classes ⇒ Object
- #response_body ⇒ Object
- #result ⇒ Object
- #serializer ⇒ Object
- #success? ⇒ Boolean
Methods included from NestedTransactionable
#auto_detect_current_transactions, #commit_transaction, #commit_transaction_if_open, #open_transaction, #opened_transactions, relevant_entity_classes_for_type, #relevant_entity_classes_for_type, #rollback_transaction, #transactions, #use_transaction
Methods included from Foobara::Concern
foobara_class_methods_module_for, foobara_concern?, included
Methods included from TruncatedInspect
Constructor Details
#initialize(**opts) ⇒ Request
Returns a new instance of Request.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 21 def initialize(**opts) valid_keys = [:inputs, :full_command_name, :action, :serializers] invalid_keys = opts.keys - valid_keys unless invalid_keys.empty? # :nocov: raise ArgumentError, "invalid keys: #{invalid_keys} expected only #{valid_keys}" # :nocov: end self.inputs = opts[:inputs] if opts.key?(:inputs) self.action = opts[:action] if opts.key?(:action) self.full_command_name = opts[:full_command_name] if opts.key?(:full_command_name) self.serializers = Util.array(opts[:serializers]) if opts.key?(:serializers) end |
Instance Attribute Details
#action ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def action @action end |
#authenticated_credential ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def authenticated_credential @authenticated_credential end |
#authenticated_user ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def authenticated_user @authenticated_user end |
#command ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def command @command end |
#command_class ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def command_class @command_class end |
#command_connector ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def command_connector @command_connector end |
#error ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def error @error end |
#full_command_name ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def full_command_name @full_command_name end |
#inputs ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def inputs @inputs end |
#response ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def response @response end |
#serializers ⇒ Object
TODO: this feels like a smell of some sort…
8 9 10 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 8 def serializers @serializers end |
Instance Method Details
#authenticate ⇒ Object
[View source]
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 47 def authenticate return if error return unless command_class.respond_to?(:requires_authentication) && command_class.requires_authentication authenticated_user, authenticated_credential = authenticator.authenticate(self) # TODO: why are these on the command instead of the request?? self.authenticated_user = authenticated_user self.authenticated_credential = authenticated_credential unless authenticated_user self.error = CommandConnector::UnauthenticatedError.new end end |
#authenticator ⇒ Object
[View source]
62 63 64 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 62 def authenticator command_class.authenticator end |
#error_collection ⇒ Object
[View source]
112 113 114 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 112 def error_collection outcome.error_collection end |
#mutate_request ⇒ Object
[View source]
38 39 40 41 42 43 44 45 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 38 def mutate_request return if error # TODO: we really need to revisit these interfaces. Something is wrong. if command_class.respond_to?(:mutate_request) command_class.mutate_request(self) end end |
#outcome ⇒ Object
[View source]
100 101 102 103 104 105 106 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 100 def outcome if error Outcome.error(error) else command&.outcome end end |
#relevant_entity_classes ⇒ Object
[View source]
116 117 118 119 120 121 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 116 def relevant_entity_classes if command_class.is_a?(::Class) && command_class < TransformedCommand entity_classes = authenticator&.relevant_entity_classes(self) [*entity_classes, *relevant_entity_classes_from_inputs_transformer] end || [] end |
#response_body ⇒ Object
[View source]
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 83 def response_body @response_body ||= begin # TODO: should we have separate ways to register success and failure serializers? body = success? ? result : error_collection if serializer serializer.process_value!(body) else body end end end |
#result ⇒ Object
[View source]
108 109 110 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 108 def result outcome.result end |
#serializer ⇒ Object
[View source]
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 66 def serializer return @serializer if defined?(@serializer) if serializers.nil? || serializers.empty? @serializer = nil return end actual_serializers = objects_to_serializers(serializers) @serializer = if actual_serializers.size == 1 actual_serializers.first else Value::Processor::Pipeline.new(processors: actual_serializers) end end |
#success? ⇒ Boolean
96 97 98 |
# File 'foobara-0.0.125/projects/command_connectors/src/command_connector/request.rb', line 96 def success? outcome.success? end |