Class: ImageServer::Installer
- Inherits:
-
Object
- Object
- ImageServer::Installer
- Defined in:
- lib/image_server/installer.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Class Method Summary collapse
Instance Method Summary collapse
- #bin_path ⇒ Object
- #current_version ⇒ Object
- #executable_name ⇒ Object
-
#initialize(configuration = ImageServer.configuration) ⇒ Installer
constructor
A new instance of Installer.
- #install ⇒ Object
- #installed_latest? ⇒ Boolean
- #platform ⇒ Object
- #remote_url ⇒ Object
- #valid_platform? ⇒ Boolean
Constructor Details
#initialize(configuration = ImageServer.configuration) ⇒ Installer
Returns a new instance of Installer.
14 15 16 |
# File 'lib/image_server/installer.rb', line 14 def initialize(configuration = ImageServer.configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/image_server/installer.rb', line 8 def configuration @configuration end |
Class Method Details
.install(configuration = ImageServer.configuration) ⇒ Object
10 11 12 |
# File 'lib/image_server/installer.rb', line 10 def self.install(configuration = ImageServer.configuration) new(configuration).install end |
Instance Method Details
#bin_path ⇒ Object
57 58 59 |
# File 'lib/image_server/installer.rb', line 57 def bin_path configuration.path_to_binary end |
#current_version ⇒ Object
39 40 41 |
# File 'lib/image_server/installer.rb', line 39 def current_version '1.18.0' end |
#executable_name ⇒ Object
43 44 45 |
# File 'lib/image_server/installer.rb', line 43 def executable_name "images-#{platform}-#{current_version}" end |
#install ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/image_server/installer.rb', line 18 def install return unless valid_platform? return if installed_latest? FileUtils.mkdir_p 'bin' File.open(bin_path, 'wb') do |saved_file| open(remote_url, 'rb') do |read_file| saved_file.write(read_file.read) end end File.chmod(744, bin_path) end |
#installed_latest? ⇒ Boolean
51 52 53 54 55 |
# File 'lib/image_server/installer.rb', line 51 def installed_latest? File.exist?(bin_path) && `#{bin_path} --version`.split(' ').last.chomp == current_version rescue false end |
#platform ⇒ Object
35 36 37 |
# File 'lib/image_server/installer.rb', line 35 def platform `uname -s`.strip.downcase end |
#remote_url ⇒ Object
47 48 49 |
# File 'lib/image_server/installer.rb', line 47 def remote_url "https://github.com/image-server/image-server/releases/download/v#{current_version}/#{executable_name}" end |
#valid_platform? ⇒ Boolean
31 32 33 |
# File 'lib/image_server/installer.rb', line 31 def valid_platform? %w(darwin linux).include?(platform) end |