Class: Terminalwire::Server::Context
- Inherits:
-
Object
- Object
- Terminalwire::Server::Context
- Extended by:
- Forwardable
- Defined in:
- lib/terminalwire/server/context.rb
Overview
Contains all of the resources that are accessible to the server on the client-side. It's the primary interface for the server to interact with the client and is integrated into other libraries like Thor, etc.
Defined Under Namespace
Classes: Env
Instance Attribute Summary collapse
-
#authority ⇒ Object
readonly
Returns the value of attribute authority.
-
#authority_path ⇒ Object
readonly
Returns the value of attribute authority_path.
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#environment_variable ⇒ Object
readonly
Returns the value of attribute environment_variable.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
readonly
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
-
#storage_path ⇒ Object
readonly
Returns the value of attribute storage_path.
Instance Method Summary collapse
- #close ⇒ Object
- #ENV ⇒ Object
- #exit(status = 0) ⇒ Object
-
#initialize(adapter:, entitlement:) ⇒ Context
constructor
A new instance of Context.
-
#warn(data = "") ⇒ Object
Direct stderr write, matching the v2 context's I/O surface so one Thor adapter (Terminalwire::V2::Server.dualize) can route
context.warnover either protocol.
Constructor Details
#initialize(adapter:, entitlement:) ⇒ Context
Returns a new instance of Context.
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 |
# File 'lib/terminalwire/server/context.rb', line 29 def initialize(adapter:, entitlement:) @adapter = adapter @entitlement = entitlement # Initialize resources @stdout = Resource::STDOUT.new("stdout", @adapter) @stdin = Resource::STDIN.new("stdin", @adapter) @stderr = Resource::STDERR.new("stderr", @adapter) @browser = Resource::Browser.new("browser", @adapter) @file = Resource::File.new("file", @adapter) @directory = Resource::Directory.new("directory", @adapter) @environment_variable = Resource::EnvironmentVariable.new("environment_variable", @adapter) # Authority is provided by the client. @authority = @entitlement.fetch(:authority) # The Terminalwire home path is provided by the client and set # as an environment variable. @root_path = Pathname.new( @environment_variable.read("TERMINALWIRE_HOME") ) # Now derive the rest of the paths from the Terminalwire home path. @authority_path = @root_path.join("authorities", @authority) @storage_path = @authority_path.join("storage") if block_given? begin yield self ensure exit end end end |
Instance Attribute Details
#authority ⇒ Object (readonly)
Returns the value of attribute authority.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def @authority end |
#authority_path ⇒ Object (readonly)
Returns the value of attribute authority_path.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def @authority_path end |
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def browser @browser end |
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def directory @directory end |
#environment_variable ⇒ Object (readonly)
Returns the value of attribute environment_variable.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def environment_variable @environment_variable end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def file @file end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def root_path @root_path end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def stderr @stderr end |
#stdin ⇒ Object (readonly)
Returns the value of attribute stdin.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def stdout @stdout end |
#storage_path ⇒ Object (readonly)
Returns the value of attribute storage_path.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def storage_path @storage_path end |
Instance Method Details
#close ⇒ Object
84 85 86 |
# File 'lib/terminalwire/server/context.rb', line 84 def close @adapter.close end |
#ENV ⇒ Object
74 75 76 |
# File 'lib/terminalwire/server/context.rb', line 74 def ENV @ENV ||= Env.new(context: self) end |
#exit(status = 0) ⇒ Object
78 79 80 81 82 |
# File 'lib/terminalwire/server/context.rb', line 78 def exit(status = 0) @adapter.write(event: "exit", status: status) ensure close end |
#warn(data = "") ⇒ Object
Direct stderr write, matching the v2 context's I/O surface so one Thor adapter
(Terminalwire::V2::Server.dualize) can route context.warn over either protocol.
25 26 27 |
# File 'lib/terminalwire/server/context.rb', line 25 def warn(data = "") @stderr.puts(data) end |