Class: Terminalwire::Binary

Inherits:
Object
  • Object
show all
Defined in:
lib/terminalwire/binary.rb

Overview

Generates Terminalwire binary file stubs. These files then run using the ‘terminalwire-exec` command.

Constant Summary collapse

SHEBANG =
"#!/usr/bin/env terminalwire-exec".freeze
ASSIGNABLE_KEYS =
%w[url]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url: nil) ⇒ Binary

Returns a new instance of Binary.



14
15
16
# File 'lib/terminalwire/binary.rb', line 14

def initialize(url: nil)
  self.url = url if url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



12
13
14
# File 'lib/terminalwire/binary.rb', line 12

def url
  @url
end

Class Method Details

.open(path) ⇒ Object



44
45
46
# File 'lib/terminalwire/binary.rb', line 44

def self.open(path)
  new.assign **YAML.safe_load_file(path)
end

.write(url:, to:) ⇒ Object



48
49
50
# File 'lib/terminalwire/binary.rb', line 48

def self.write(url:, to:)
  new(url: url).write to
end

Instance Method Details

#assign(**hash) ⇒ Object



29
30
31
32
33
34
# File 'lib/terminalwire/binary.rb', line 29

def assign(**hash)
  ASSIGNABLE_KEYS.each do |key|
    public_send "#{key}=", hash[key] if hash.key? key
  end
  self
end

#bodyObject



22
23
24
25
26
27
# File 'lib/terminalwire/binary.rb', line 22

def body
  <<~BASH
    #{SHEBANG}
    url: "#{url.to_s}"
  BASH
end

#write(path) ⇒ Object

Writes the binary to the given path.



37
38
39
40
41
42
# File 'lib/terminalwire/binary.rb', line 37

def write(path)
  File.open(path, "w") do |file|
    file.write body
    file.chmod 0755
  end
end