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
10 11 12 |
# File 'lib/react_native_util/util.rb', line 10 def platform @platform end |
Instance Method Details
#boolean_env_var?(var, default_value: false) ⇒ Boolean
Return a Boolean value associated with an environment variable.
37 38 39 40 41 42 |
# File 'lib/react_native_util/util.rb', line 37 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.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/react_native_util/util.rb', line 21 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.
49 50 51 52 53 54 |
# File 'lib/react_native_util/util.rb', line 49 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
66 67 68 |
# File 'lib/react_native_util/util.rb', line 66 def log() STDOUT.log end |
#mac? ⇒ Boolean
Convenience method to determine if running on a Mac.
59 60 61 62 |
# File 'lib/react_native_util/util.rb', line 59 def mac? @platform ||= TTY::Platform.new @platform.mac? end |