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



26
27
28
# File 'lib/shakapacker/utils/misc.rb', line 26

def self.object_to_boolean(value)
  [true, "true", "yes", 1, "1", "t"].include?(value.instance_of?(String) ? value.downcase : value)
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



31
32
33
# File 'lib/shakapacker/utils/misc.rb', line 31

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)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/shakapacker/utils/misc.rb', line 11

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