Class: Terminalwire::Client::Handler
- Inherits:
-
Object
- Object
- Terminalwire::Client::Handler
- Includes:
- Logging
- Defined in:
- lib/terminalwire/client/handler.rb
Overview
The handler is the main class that connects to the Terminalwire server and dispatches messages to the appropriate resources.
Constant Summary collapse
- VERSION =
The version of the Terminalwire client.
Terminalwire::VERSION
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#entitlement ⇒ Object
Returns the value of attribute entitlement.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
Instance Method Summary collapse
- #connect ⇒ Object
- #handle(message) ⇒ Object
-
#initialize(adapter, arguments: ARGV, program_name: $0, endpoint:) {|_self| ... } ⇒ Handler
constructor
A new instance of Handler.
- #verify_license ⇒ Object
Constructor Details
#initialize(adapter, arguments: ARGV, program_name: $0, endpoint:) {|_self| ... } ⇒ Handler
Returns a new instance of Handler.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/terminalwire/client/handler.rb', line 13 def initialize(adapter, arguments: ARGV, program_name: $0, endpoint:) @endpoint = endpoint @adapter = adapter @program_arguments = arguments @program_name = program_name @entitlement = Entitlement::Policy.resolve(authority: @endpoint.) yield self if block_given? @resources = Resource::Handler.new do |it| it << Resource::STDOUT.new("stdout", @adapter, entitlement:) it << Resource::STDIN.new("stdin", @adapter, entitlement:) it << Resource::STDERR.new("stderr", @adapter, entitlement:) it << Resource::Browser.new("browser", @adapter, entitlement:) it << Resource::File.new("file", @adapter, entitlement:) it << Resource::Directory.new("directory", @adapter, entitlement:) it << Resource::EnvironmentVariable.new("environment_variable", @adapter, entitlement:) end end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
10 11 12 |
# File 'lib/terminalwire/client/handler.rb', line 10 def adapter @adapter end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
10 11 12 |
# File 'lib/terminalwire/client/handler.rb', line 10 def endpoint @endpoint end |
#entitlement ⇒ Object
Returns the value of attribute entitlement.
11 12 13 |
# File 'lib/terminalwire/client/handler.rb', line 11 def entitlement @entitlement end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
10 11 12 |
# File 'lib/terminalwire/client/handler.rb', line 10 def resources @resources end |
Instance Method Details
#connect ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/terminalwire/client/handler.rb', line 41 def connect verify_license @adapter.write( event: "initialization", protocol: { version: VERSION }, entitlement: @entitlement.serialize, program: { name: @program_name, arguments: @program_arguments } ) loop do handle @adapter.read end end |
#handle(message) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/terminalwire/client/handler.rb', line 59 def handle() case in { event: "resource", action: "command", name:, parameters: } @resources.dispatch(**) in { event: "exit", status: } exit Integer(status) end end |
#verify_license ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/terminalwire/client/handler.rb', line 33 def verify_license # Connect to the Terminalwire license server to verify the URL endpoint # and displays a message to the user, if any are present. $stdout.print ServerLicenseVerification.new(url: @endpoint.to_url). rescue $stderr.puts "Failed to verify server license." end |