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.
Constructor Details
#initialize(adapter:, entitlement:) ⇒ Context
Returns a new instance of Context.
23 24 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 |
# File 'lib/terminalwire/server/context.rb', line 23 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. = @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. = @root_path.join("authorities", ) @storage_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 end |
#authority_path ⇒ Object (readonly)
Returns the value of attribute authority_path.
10 11 12 |
# File 'lib/terminalwire/server/context.rb', line 10 def 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
76 77 78 |
# File 'lib/terminalwire/server/context.rb', line 76 def close @adapter.close end |
#ENV ⇒ Object
68 69 70 |
# File 'lib/terminalwire/server/context.rb', line 68 def ENV @ENV ||= Env.new(context: self) end |
#exit(status = 0) ⇒ Object
72 73 74 |
# File 'lib/terminalwire/server/context.rb', line 72 def exit(status = 0) @adapter.write(event: "exit", status: status) end |