class Revealing::Prerequisite
Attributes
command[R]
to_s[R]
Public Class Methods
new(command, details = nil)
click to toggle source
# File lib/revealing/prerequisite.rb, line 8 def initialize(command, details = nil) @command = command case details when NilClass @package_info = same_as_command(command) when String @package_info = different_but_same_on_all_platforms(details) when Hash @package_info = different_for_each_platform(details) when Proc @package_info = callable(details) else raise "Don't know how to interpret '#{package_info.inspect}' as package info." end end
Public Instance Methods
available?()
click to toggle source
# File lib/revealing/prerequisite.rb, line 25 def available? system("sh -c 'command -v #{command} > /dev/null'") end
install_hint()
click to toggle source
# File lib/revealing/prerequisite.rb, line 29 def install_hint @package_info[Gem::Platform.local.os.to_sym] end
Private Instance Methods
callable(details)
click to toggle source
# File lib/revealing/prerequisite.rb, line 56 def callable(details) { darwin: details.call(:darwin), linux: details.call(:linux), } end
different_but_same_on_all_platforms(details)
click to toggle source
# File lib/revealing/prerequisite.rb, line 42 def different_but_same_on_all_platforms(details) { darwin: "brew install #{details}", linux: "apt install #{details}", } end
different_for_each_platform(details)
click to toggle source
# File lib/revealing/prerequisite.rb, line 49 def different_for_each_platform(details) { darwin: "brew install #{details[:darwin]}", linux: "apt install #{details[:linux]}", } end
same_as_command(command)
click to toggle source
# File lib/revealing/prerequisite.rb, line 35 def same_as_command(command) { darwin: "brew install #{command}", linux: "apt install #{command}", } end