Class: TalkToYourApp::Tool::Context
- Inherits:
-
Object
- Object
- TalkToYourApp::Tool::Context
- Defined in:
- lib/talk_to_your_app/tool.rb
Overview
The context handed to #call. Exposes the request principal and session,
the audit logger, and role-switched database connections.
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#connection(name = nil, &block) ⇒ Object
Runs the block against a registry connection, switched to its declared role, and records the resolved name so #connection_name reports the same connection the block ran on (even when an explicit override was passed).
-
#connection_name ⇒ Object
The connection name this call resolves to — the one a prior #connection call ran on, or the default resolution when #connection has not run yet.
-
#initialize(tool_class:, plugin_name: nil, logger: nil) ⇒ Context
constructor
A new instance of Context.
- #ip ⇒ Object
- #principal ⇒ Object
- #session_id ⇒ Object
Constructor Details
#initialize(tool_class:, plugin_name: nil, logger: nil) ⇒ Context
Returns a new instance of Context.
35 36 37 38 39 |
# File 'lib/talk_to_your_app/tool.rb', line 35 def initialize(tool_class:, plugin_name: nil, logger: nil) @tool_class = tool_class @plugin_name = plugin_name @logger = logger end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
33 34 35 |
# File 'lib/talk_to_your_app/tool.rb', line 33 def logger @logger end |
Instance Method Details
#connection(name = nil, &block) ⇒ Object
Runs the block against a registry connection, switched to its declared role, and records the resolved name so #connection_name reports the same connection the block ran on (even when an explicit override was passed).
56 57 58 59 |
# File 'lib/talk_to_your_app/tool.rb', line 56 def connection(name = nil, &block) @connection_name = resolve_connection_name(name) TalkToYourApp::ConnectionRegistry.with(@connection_name, &block) end |
#connection_name ⇒ Object
The connection name this call resolves to — the one a prior #connection
call ran on, or the default resolution when #connection has not run yet.
timeout_ms-style code reads this so the timeout is fetched from the
same spec the query runs on. Pure no-arg reader: pass an override to
#connection, not here.
66 67 68 |
# File 'lib/talk_to_your_app/tool.rb', line 66 def connection_name @connection_name || resolve_connection_name(nil) end |
#ip ⇒ Object
49 50 51 |
# File 'lib/talk_to_your_app/tool.rb', line 49 def ip TalkToYourApp::Current.ip end |
#principal ⇒ Object
41 42 43 |
# File 'lib/talk_to_your_app/tool.rb', line 41 def principal TalkToYourApp::Current.principal end |
#session_id ⇒ Object
45 46 47 |
# File 'lib/talk_to_your_app/tool.rb', line 45 def session_id TalkToYourApp::Current.session_id end |