Module: ReactNativeUtil::Util
Overview
Module with utility methods
Instance Attribute Summary collapse
-
#platform ⇒ Object
readonly
- TTY::Platform
-
Object with platform information.
Instance Method Summary collapse
-
#boolean_env_var?(var, default_value: false) ⇒ Boolean
Return a Boolean value associated with an environment variable.
-
#execute(*command, chdir: nil, output: STDOUT, log: STDOUT) ⇒ Object
Execute the specified command.
-
#float_env_var(var, default_value: 0) ⇒ Float
Return a Float value associated with an environment variable.
-
#log(message) ⇒ Object
Wrapper for STDOUT.log.
-
#mac? ⇒ Boolean
Convenience method to determine if running on a Mac.
Instance Attribute Details
#platform ⇒ Object (readonly)
- TTY::Platform
-
Object with platform information
9 10 11 |
# File 'lib/react_native_util/util.rb', line 9 def platform @platform end |
Instance Method Details
#boolean_env_var?(var, default_value: false) ⇒ Boolean
Return a Boolean value associated with an environment variable.
36 37 38 39 40 41 |
# File 'lib/react_native_util/util.rb', line 36 def boolean_env_var?(var, default_value: false) value = ENV[var.to_s] return default_value if value.nil? /^(y|t)/i.match? value end |
#execute(*command, chdir: nil, output: STDOUT, log: STDOUT) ⇒ Object
Execute the specified command. If output is non-nil, generate a log at that location. Main log (open) is log.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/react_native_util/util.rb', line 20 def execute(*command, chdir: nil, output: STDOUT, log: STDOUT) log.log_command command unless log.nil? = chdir.nil? ? {} : { chdir: chdir } system(*command, .merge(%i[err out] => output)) raise ExecutionError unless $?.success? nil end |
#float_env_var(var, default_value: 0) ⇒ Float
Return a Float value associated with an environment variable.
48 49 50 51 52 53 |
# File 'lib/react_native_util/util.rb', line 48 def float_env_var(var, default_value: 0) value = ENV[var.to_s] return default_value.to_f if value.nil? value.to_f end |
#log(message) ⇒ Object
Wrapper for STDOUT.log
65 66 67 |
# File 'lib/react_native_util/util.rb', line 65 def log() STDOUT.log end |
#mac? ⇒ Boolean
Convenience method to determine if running on a Mac.
58 59 60 61 |
# File 'lib/react_native_util/util.rb', line 58 def mac? @platform ||= TTY::Platform.new @platform.mac? end |