Module: ReactNativeUtil::Util

Included in:
CLI, Converter
Defined in:
lib/react_native_util/util.rb

Overview

Module with utility methods

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#platformObject (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.

Raises:

  • ExecutionError If the command fails



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?

  options = chdir.nil? ? {} : { chdir: chdir }
  system(*command, options.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(message)
  STDOUT.log message
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