class BranchIOCLI::Configuration::Environment

Constants

PLATFORM

Public Class Methods

assets_path() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 56
def assets_path
  File.join lib_path, "assets"
end
completion_script() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 67
def completion_script
  path = File.join assets_path, "completions", "completion.#{shell}"
  path if File.readable?(path)
end
config() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 11
def config
  Configuration.current
end
display_path(path) click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 100
def display_path(path)
  return nil if path.nil?
  path = path.gsub(Gem.dir, '$GEM_HOME')
  path = obfuscate_user(path)
  path
end
from_homebrew?() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 48
def from_homebrew?
  ENV["BRANCH_IO_CLI_INSTALLED_FROM_HOMEBREW"] == "true"
end
header_item(label, value, terminal: true) click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 87
def header_item(label, value, terminal: true)
  if terminal
    "<%= color('#{label}:', BOLD) %> #{value}\n"
  else
    "#{label}: #{value}\n"
  end
end
lib_path() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 52
def lib_path
  File.expand_path File.join("..", "..", ".."), __FILE__
end
obfuscate_user(path) click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 95
def obfuscate_user(path)
  return nil if path.nil?
  path.gsub(ENV['HOME'], '~').gsub(ENV['USER'], '$USER')
end
operating_system() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 27
def operating_system
  if PLATFORM.br_high_sierra?
    os = "macOS High Sierra"
  elsif PLATFORM.br_sierra?
    os = "macOS Sierra"
  else
    os = os_name if os_name
    os += " #{os_version}" if os_version
  end

  os += " (#{os_arch})"

  os
end
os_arch() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 23
def os_arch
  PLATFORM.architecture
end
os_name() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 19
def os_name
  PLATFORM.os.to_s.capitalize
end
os_version() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 15
def os_version
  PLATFORM.version
end
ruby_header(terminal: true, include_load_path: false) click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 72
def ruby_header(terminal: true, include_load_path: false)
  header = header_item("Operating system", operating_system, terminal: terminal)
  header += header_item("Ruby version", RUBY_VERSION, terminal: terminal)
  header += header_item("Ruby path", display_path(ruby_path), terminal: terminal)
  header += header_item("RubyGems version", Gem::VERSION, terminal: terminal)
  header += header_item("Bundler", defined?(Bundler) ? Bundler::VERSION : "no", terminal: terminal)
  header += header_item("Installed from Homebrew", from_homebrew? ? "yes" : "no", terminal: terminal)
  header += header_item("GEM_HOME", obfuscate_user(Gem.dir), terminal: terminal)
  header += header_item("Lib path", display_path(lib_path), terminal: terminal)
  header += header_item("LOAD_PATH", $LOAD_PATH.map { |p| display_path(p) }, terminal: terminal) if include_load_path
  header += header_item("Shell", ENV["SHELL"], terminal: terminal)
  header += "\n"
  header
end
ruby_path() click to toggle source
# File lib/branch_io_cli/configuration/environment.rb, line 42
def ruby_path
  File.join(RbConfig::CONFIG["bindir"],
            RbConfig::CONFIG["RUBY_INSTALL_NAME"] +
            RbConfig::CONFIG["EXEEXT"])
end
shell() click to toggle source

Returns the last path component. Uses the SHELL env. var. unless overriden at the command line (br env -cs zsh).

# File lib/branch_io_cli/configuration/environment.rb, line 62
def shell
  return ENV["SHELL"].split("/").last unless config.class.available_options.map(&:name).include?(:shell)
  config.shell.split("/").last
end