Class: BranchIOCLI::Configuration::Environment
- Inherits:
-
Object
- Object
- BranchIOCLI::Configuration::Environment
- Defined in:
- lib/branch_io_cli/configuration/environment.rb
Constant Summary collapse
Class Method Summary collapse
- .assets_path ⇒ Object
- .completion_script ⇒ Object
- .config ⇒ Object
- .display_path(path) ⇒ Object
- .from_homebrew? ⇒ Boolean
- .header_item(label, value, terminal: true) ⇒ Object
- .lib_path ⇒ Object
- .obfuscate_user(path) ⇒ Object
- .operating_system ⇒ Object
- .os_arch ⇒ Object
- .os_name ⇒ Object
- .os_version ⇒ Object
- .ruby_header(terminal: true, include_load_path: false) ⇒ Object
- .ruby_path ⇒ Object
-
.shell ⇒ Object
Returns the last path component.
Class Method Details
.assets_path ⇒ Object
56 57 58 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 56 def assets_path File.join lib_path, "assets" end |
.completion_script ⇒ Object
67 68 69 70 |
# 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 ⇒ Object
11 12 13 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 11 def config Configuration.current end |
.display_path(path) ⇒ Object
99 100 101 102 103 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 99 def display_path(path) path = path.gsub(Gem.dir, '$GEM_HOME') path = obfuscate_user(path) path end |
.from_homebrew? ⇒ Boolean
48 49 50 |
# 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) ⇒ Object
87 88 89 90 91 92 93 |
# 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 ⇒ Object
52 53 54 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 52 def lib_path File. File.join("..", "..", ".."), __FILE__ end |
.obfuscate_user(path) ⇒ Object
95 96 97 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 95 def obfuscate_user(path) path.gsub(ENV['HOME'], '~').gsub(ENV['USER'], '$USER') end |
.operating_system ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 27 def 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 ⇒ Object
23 24 25 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 23 def os_arch PLATFORM.architecture end |
.os_name ⇒ Object
19 20 21 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 19 def os_name PLATFORM.os.to_s.capitalize end |
.os_version ⇒ Object
15 16 17 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 15 def os_version PLATFORM.version end |
.ruby_header(terminal: true, include_load_path: false) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 72 def ruby_header(terminal: true, include_load_path: false) header = header_item("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 ⇒ Object
42 43 44 45 46 |
# 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 ⇒ Object
Returns the last path component. Uses the SHELL env. var. unless overriden at the command line (br env -cs zsh).
62 63 64 65 |
# File 'lib/branch_io_cli/configuration/environment.rb', line 62 def shell return ENV["SHELL"].split("/").last unless config.class..map(&:name).include?(:shell) config.shell.split("/").last end |