Class: Terminalwire::Client::Exec
- Inherits:
-
Object
- Object
- Terminalwire::Client::Exec
- Defined in:
- lib/terminalwire/client/exec.rb
Overview
Called by the ‘terminalwire-exec` shebang in scripts. This makes it easy for people to create their own scripts that use Terminalwire that look like this:
“‘sh #!/usr/bin/env terminalwire-exec url: “terminalwire.com/terminal” “`
These files are saved, then ‘chmod + x` is run on them and they become executable.
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path:, arguments:) ⇒ Exec
constructor
A new instance of Exec.
- #start ⇒ Object
Constructor Details
#initialize(path:, arguments:) ⇒ Exec
Returns a new instance of Exec.
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/terminalwire/client/exec.rb', line 18 def initialize(path:, arguments:) @arguments = arguments @path = Pathname.new(path) @configuration = YAML.safe_load_file(@path) @url = URI(@configuration.fetch("url")) rescue Errno::ENOENT => e raise Terminalwire::Error, "File not found: #{@path}" rescue URI::InvalidURIError => e raise Terminalwire::Error, "Invalid URI: #{@url}" rescue KeyError => e raise Terminalwire::Error, "Missing key in configuration: #{e}" end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
16 17 18 |
# File 'lib/terminalwire/client/exec.rb', line 16 def arguments @arguments end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
16 17 18 |
# File 'lib/terminalwire/client/exec.rb', line 16 def configuration @configuration end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
16 17 18 |
# File 'lib/terminalwire/client/exec.rb', line 16 def path @path end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
16 17 18 |
# File 'lib/terminalwire/client/exec.rb', line 16 def url @url end |
Class Method Details
.start ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/terminalwire/client/exec.rb', line 35 def self.start case ARGV in path, *arguments new(path:, arguments:).start end rescue NoMatchingPatternError => e raise Terminalwire::Error, "Launched with incorrect arguments: #{ARGV}" end |
Instance Method Details
#start ⇒ Object
31 32 33 |
# File 'lib/terminalwire/client/exec.rb', line 31 def start Terminalwire::Client.websocket(url:, arguments:) end |