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.
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_directories ⇒ 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.
5 6 7 8 |
# File 'lib/completely/installer.rb', line 5 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.
3 4 5 |
# File 'lib/completely/installer.rb', line 3 def program @program end |
#script_path ⇒ Object (readonly)
Returns the value of attribute script_path.
3 4 5 |
# File 'lib/completely/installer.rb', line 3 def script_path @script_path end |
Instance Method Details
#install(force: false) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/completely/installer.rb', line 41 def install(force: false) unless completions_path raise InstallError, 'Cannot determine system completions directory' end unless script_exist? raise InstallError, "Cannot find script: m`#{script_path}`" end if target_exist? && !force raise InstallError, "File exists: m`#{target_path}`" end system(*install_command) end |
#install_command ⇒ Object
19 20 21 22 |
# File 'lib/completely/installer.rb', line 19 def install_command result = root_user? ? [] : %w[sudo] result + %W[cp #{script_path} #{target_path}] end |
#install_command_string ⇒ Object
24 25 26 |
# File 'lib/completely/installer.rb', line 24 def install_command_string install_command.join ' ' end |
#target_directories ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/completely/installer.rb', line 10 def target_directories @target_directories ||= %W[ /usr/share/bash-completion/completions /usr/local/etc/bash_completion.d #{Dir.home}/.local/share/bash-completion/completions #{Dir.home}/.bash_completion.d ] end |
#target_path ⇒ Object
37 38 39 |
# File 'lib/completely/installer.rb', line 37 def target_path "#{completions_path}/#{program}" end |
#uninstall ⇒ Object
57 58 59 |
# File 'lib/completely/installer.rb', line 57 def uninstall system(*uninstall_command) end |
#uninstall_command ⇒ Object
28 29 30 31 |
# File 'lib/completely/installer.rb', line 28 def uninstall_command result = root_user? ? [] : %w[sudo] result + %w[rm -f] + target_directories.map { |dir| "#{dir}/#{program}" } end |
#uninstall_command_string ⇒ Object
33 34 35 |
# File 'lib/completely/installer.rb', line 33 def uninstall_command_string uninstall_command.join ' ' end |