Class: Shakapacker::Utils::Misc

Inherits:
Object
  • Object
show all
Extended by:
FileUtils
Defined in:
lib/shakapacker/utils/misc.rb

Class Method Summary collapse

Class Method Details

.object_to_boolean(value) ⇒ Object



38
39
40
# File 'lib/shakapacker/utils/misc.rb', line 38

def self.object_to_boolean(value)
  [true, "true", "yes", 1, "1", "t"].include?(value.instance_of?(String) ? value.downcase : value)
end

.require_package_json_gemObject



15
16
17
18
19
20
21
# File 'lib/shakapacker/utils/misc.rb', line 15

def self.require_package_json_gem
  unless use_package_json_gem
    raise "PackageJson should not be used unless SHAKAPACKER_USE_PACKAGE_JSON_GEM is true"
  end

  require "package_json"
end

.sh_in_dir(dir, *shell_commands) ⇒ Object

Executes a string or an array of strings in a shell in the given directory in an unbundled environment



43
44
45
# File 'lib/shakapacker/utils/misc.rb', line 43

def self.sh_in_dir(dir, *shell_commands)
  shell_commands.flatten.each { |shell_command| sh %(cd '#{dir}' && #{shell_command.strip}) }
end

.uncommitted_changes?(message_handler) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shakapacker/utils/misc.rb', line 23

def self.uncommitted_changes?(message_handler)
  return false if ENV["COVERAGE"] == "true"

  status = `git status --porcelain`
  return false if $CHILD_STATUS.success? && status.empty?

  error = if $CHILD_STATUS.success?
    "You have uncommitted code. Please commit or stash your changes before continuing"
          else
            "You do not have Git installed. Please install Git, and commit your changes before continuing"
  end
  message_handler.add_error(error)
  true
end

.use_package_json_gemObject



11
12
13
# File 'lib/shakapacker/utils/misc.rb', line 11

def self.use_package_json_gem
  ENV.fetch("SHAKAPACKER_USE_PACKAGE_JSON_GEM", "false").casecmp("true").zero?
end