Module: Rori18n::Installer

Defined in:
lib/rori18n/installer.rb

Constant Summary collapse

GITHUB_REPO =
"bobadilla-tech/rori18n"

Class Method Summary collapse

Class Method Details

.binary_pathObject



14
15
16
# File 'lib/rori18n/installer.rb', line 14

def self.binary_path
  File.join(cache_dir, "rori18n-#{CLI_VERSION}-#{Platform.asset_name}")
end

.cache_dirObject



10
11
12
# File 'lib/rori18n/installer.rb', line 10

def self.cache_dir
  File.expand_path("~/.rori18n/bin")
end

.install!Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rori18n/installer.rb', line 22

def self.install!
  return if installed?

  asset = Platform.asset_name
  url   = "https://github.com/#{GITHUB_REPO}/releases/download/v#{CLI_VERSION}/#{asset}"

  $stderr.puts "[rori18n] Downloading binary for #{asset} (v#{CLI_VERSION})..."
  $stderr.puts "[rori18n] Source: #{url}"

  FileUtils.mkdir_p(cache_dir)

  download(url, binary_path)
  FileUtils.chmod(0o755, binary_path)

  $stderr.puts "[rori18n] Installed to #{binary_path}"
rescue Rori18n::Error
  raise
rescue => e
  raise Rori18n::Error, "Failed to install rori18n binary: #{e.message}\n" \
    "You can manually download from https://github.com/#{GITHUB_REPO}/releases"
end

.installed?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/rori18n/installer.rb', line 18

def self.installed?
  File.exist?(binary_path) && File.executable?(binary_path)
end