Module: U3dCore::Helper
- Defined in:
- lib/u3d_core/helper.rb
Constant Summary collapse
- DEFAULT_LINUX_PATH =
File.join(ENV['HOME'], '.u3d').freeze
- DEFAULT_MAC_PATH =
File.join(ENV['HOME'], 'Library', 'Application Support', 'u3d').freeze
- DEFAULT_WINDOWS_PATH =
File.join(ENV['HOME'], 'AppData', 'Local', 'u3d').freeze
Class Method Summary collapse
-
.backticks(command, print: true) ⇒ Object
Runs a given command using backticks (‘) and prints them out using the UI.command method.
-
.bundler? ⇒ boolean
True if executing with bundler (like ‘bundle exec fastlane [action]’).
-
.ci? ⇒ boolean
True if building in a known CI environment.
-
.colors_disabled? ⇒ Boolean
Do we want to disable the colored output?.
- .data_path ⇒ Object
-
.iterm? ⇒ Boolean
Does the user use iTerm?.
- .linux? ⇒ Boolean
-
.mac? ⇒ Boolean
Is the currently running computer a Mac?.
-
.mac_stock_terminal? ⇒ Boolean
Does the user use the Mac stock terminal.
-
.operating_system ⇒ Object
the current operating system.
-
.operating_systems ⇒ Object
the valid operating systems.
-
.strip_ansi_colors(str) ⇒ Object
removes ANSI colors from string.
-
.test? ⇒ Boolean
True if the currently running program is a unit test.
- .ubuntu_on_windows? ⇒ Boolean
- .win_32? ⇒ Boolean
- .win_64? ⇒ Boolean
- .windows? ⇒ Boolean
- .windows_path(path) ⇒ Object
Class Method Details
.backticks(command, print: true) ⇒ Object
Runs a given command using backticks (‘) and prints them out using the UI.command method
52 53 54 55 56 57 |
# File 'lib/u3d_core/helper.rb', line 52 def self.backticks(command, print: true) UI.command(command) if print result = `#{command}` UI.command_output(result) if print return result end |
.bundler? ⇒ boolean
Returns true if executing with bundler (like ‘bundle exec fastlane [action]’).
70 71 72 73 74 75 76 |
# File 'lib/u3d_core/helper.rb', line 70 def self.bundler? # Bundler environment variable %w[BUNDLE_BIN_PATH BUNDLE_GEMFILE].each do |current| return true if ENV.key?(current) end return false end |
.ci? ⇒ boolean
Returns true if building in a known CI environment.
79 80 81 82 83 84 85 |
# File 'lib/u3d_core/helper.rb', line 79 def self.ci? # Check for Jenkins, Travis CI, ... environment variables %w[JENKINS_HOME JENKINS_URL TRAVIS CIRCLECI CI TEAMCITY_VERSION GO_PIPELINE_NAME bamboo_buildKey GITLAB_CI XCS].each do |current| return true if ENV.key?(current) end return false end |
.colors_disabled? ⇒ Boolean
Do we want to disable the colored output?
140 141 142 |
# File 'lib/u3d_core/helper.rb', line 140 def self.colors_disabled? ENV["U3D_DISABLE_COLORS"] end |
.data_path ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/u3d_core/helper.rb', line 35 def self.data_path case when :linux DEFAULT_LINUX_PATH when :mac DEFAULT_MAC_PATH when :win DEFAULT_WINDOWS_PATH end end |
.iterm? ⇒ Boolean
Does the user use iTerm?
150 151 152 |
# File 'lib/u3d_core/helper.rb', line 150 def self.iterm? !ENV["ITERM_SESSION_ID"].nil? end |
.linux? ⇒ Boolean
92 93 94 |
# File 'lib/u3d_core/helper.rb', line 92 def self.linux? (/linux/ =~ RUBY_PLATFORM) != nil end |
.mac? ⇒ Boolean
Is the currently running computer a Mac?
107 108 109 |
# File 'lib/u3d_core/helper.rb', line 107 def self.mac? (/darwin/ =~ RUBY_PLATFORM) != nil end |
.mac_stock_terminal? ⇒ Boolean
Does the user use the Mac stock terminal
145 146 147 |
# File 'lib/u3d_core/helper.rb', line 145 def self.mac_stock_terminal? !ENV["TERM_PROGRAM_VERSION"].nil? end |
.operating_system ⇒ Object
the current operating system
117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/u3d_core/helper.rb', line 117 def self. # rubocop:disable Style/GuardClause if linux? return :linux elsif mac? return :mac elsif windows? return :win else raise 'Could not assume what OS you\'re running, please specify it as much as possible' end # rubocop:enable Style/GuardClause end |
.operating_systems ⇒ Object
the valid operating systems
112 113 114 |
# File 'lib/u3d_core/helper.rb', line 112 def self. i[linux mac win] end |
.strip_ansi_colors(str) ⇒ Object
removes ANSI colors from string
65 66 67 |
# File 'lib/u3d_core/helper.rb', line 65 def self.strip_ansi_colors(str) str.gsub(/\e\[([;\d]+)?m/, '') end |
.test? ⇒ Boolean
Returns true if the currently running program is a unit test.
60 61 62 |
# File 'lib/u3d_core/helper.rb', line 60 def self.test? defined? SpecHelper end |
.ubuntu_on_windows? ⇒ Boolean
96 97 98 99 100 101 102 103 104 |
# File 'lib/u3d_core/helper.rb', line 96 def self.ubuntu_on_windows? # taken from: https://github.com/Microsoft/BashOnWindows/issues/423#issuecomment-221627364 proc_version = '/proc/version' return false unless File.exist? proc_version File.open(proc_version, 'r') do |f| return !(/Microsof|WSL/ =~ f.read).nil? end end |
.win_32? ⇒ Boolean
135 136 137 |
# File 'lib/u3d_core/helper.rb', line 135 def self.win_32? (/i386/ =~ RUBY_PLATFORM) != nil end |
.win_64? ⇒ Boolean
131 132 133 |
# File 'lib/u3d_core/helper.rb', line 131 def self.win_64? (/x64/ =~ RUBY_PLATFORM) != nil end |
.windows? ⇒ Boolean
87 88 89 90 |
# File 'lib/u3d_core/helper.rb', line 87 def self.windows? # taken from: http://stackoverflow.com/a/171011/1945875 (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil end |
.windows_path(path) ⇒ Object
46 47 48 |
# File 'lib/u3d_core/helper.rb', line 46 def self.windows_path(path) path.gsub(%r{/(\d)}, '/\\\\\1').tr('/', '\\') end |