Module: Musical::Util

Included in:
Musical, DVD, DVD, DVD::Chapter
Defined in:
lib/musical/util.rb

Constant Summary collapse

REQUIRED_APPS =
%w(dvdbackup ffmpeg).freeze

Instance Method Summary collapse

Instance Method Details

#check_envObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/musical/util.rb', line 6

def check_env
  REQUIRED_APPS.each do |app|
    unless installed?(app)
      messages = []
      messages << "'#{app}' is not installed."
      messages << "Try this command to install '#{app}'."
      messages << ""
      messages << "   brew install #{app}"
      messages << ""
      raise RuntimeError, messages.join("\n")
    end
  end
  true
end

#execute_command(cmd, silent = false) ⇒ Object



25
26
27
28
29
# File 'lib/musical/util.rb', line 25

def execute_command(cmd, silent = false)
  cmd << ' 2>/dev/null' if silent
  execute_out, _ = *Open3.capture2(cmd)
  execute_out
end

#installed?(app) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/musical/util.rb', line 21

def installed?(app)
  !execute_command("which #{app}").empty?
end