Class: Completely::Installer
- Inherits:
-
Object
- Object
- Completely::Installer
- Defined in:
- lib/completely/installer.rb
Instance Attribute Summary collapse
-
#program ⇒ Object
readonly
Returns the value of attribute program.
-
#script_path ⇒ Object
readonly
Returns the value of attribute script_path.
Class Method Summary collapse
- .create_tempfile ⇒ Object
- .from_io(program:, io: nil) ⇒ Object
- .from_string(program:, string:) ⇒ Object
- .tempfiles ⇒ Object
Instance Method Summary collapse
-
#initialize(program:, script_path: nil) ⇒ Installer
constructor
A new instance of Installer.
- #install(force: false) ⇒ Object
- #install_command ⇒ Object
- #install_command_string ⇒ Object
- #target_path ⇒ Object
- #uninstall ⇒ Object
- #uninstall_command ⇒ Object
- #uninstall_command_string ⇒ Object
Constructor Details
#initialize(program:, script_path: nil) ⇒ Installer
Returns a new instance of Installer.
38 39 40 41 |
# File 'lib/completely/installer.rb', line 38 def initialize(program:, script_path: nil) @program = program @script_path = script_path end |
Instance Attribute Details
#program ⇒ Object (readonly)
Returns the value of attribute program.
36 37 38 |
# File 'lib/completely/installer.rb', line 36 def program @program end |
#script_path ⇒ Object (readonly)
Returns the value of attribute script_path.
36 37 38 |
# File 'lib/completely/installer.rb', line 36 def script_path @script_path end |
Class Method Details
.create_tempfile ⇒ Object
27 28 29 30 31 |
# File 'lib/completely/installer.rb', line 27 def create_tempfile tempfile = Tempfile.new ['completely-', '.bash'] tempfiles.push tempfile tempfile end |
.from_io(program:, io: nil) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/completely/installer.rb', line 6 def from_io(program:, io: nil) io ||= $stdin raise InstallError, 'io must respond to #read' unless io.respond_to?(:read) raise InstallError, 'io is closed' if io.respond_to?(:closed?) && io.closed? from_string program:, string: io.read end |
.from_string(program:, string:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/completely/installer.rb', line 15 def from_string(program:, string:) tempfile = create_tempfile script_path = tempfile.path begin File.write script_path, string ensure tempfile.close end new program:, script_path: end |
.tempfiles ⇒ Object
33 |
# File 'lib/completely/installer.rb', line 33 def tempfiles = @tempfiles ||= [] |
Instance Method Details
#install(force: false) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/completely/installer.rb', line 63 def install(force: false) unless script_exist? raise InstallError, "Cannot find script: m`#{script_path}`" end FileUtils.mkdir_p completions_path if target_exist? && !force raise InstallError, "File exists: m`#{target_path}`" end system(*install_command) end |
#install_command ⇒ Object
43 44 45 |
# File 'lib/completely/installer.rb', line 43 def install_command %W[cp #{script_path} #{target_path}] end |
#install_command_string ⇒ Object
47 48 49 |
# File 'lib/completely/installer.rb', line 47 def install_command_string install_command.join ' ' end |
#target_path ⇒ Object
59 60 61 |
# File 'lib/completely/installer.rb', line 59 def target_path "#{completions_path}/#{program}" end |
#uninstall ⇒ Object
77 78 79 |
# File 'lib/completely/installer.rb', line 77 def uninstall system(*uninstall_command) end |
#uninstall_command ⇒ Object
51 52 53 |
# File 'lib/completely/installer.rb', line 51 def uninstall_command %W[rm -f #{target_path}] end |
#uninstall_command_string ⇒ Object
55 56 57 |
# File 'lib/completely/installer.rb', line 55 def uninstall_command_string uninstall_command.join ' ' end |