class Bindep::Context
Attributes
no_confirm_before_install[RW]
no_install[RW]
silent_exceptions[RW]
Public Class Methods
new()
click to toggle source
Create a new Bindep
context with its own options and item registry.
# File lib/bindep/context.rb, line 6 def initialize @registry = {} @no_install = false @no_confirm_before_install = false @silent_exceptions = false unless Helpers.which_test error "Command detection does not work on your system. Bindep cannot run on your system!" end end
Public Instance Methods
check(id, force_install = false, &block)
click to toggle source
Check if a given item is installed, can also define item beforehand if block is given.
# File lib/bindep/context.rb, line 27 def check(id, force_install = false, &block) item = block_given? ? define(id, &block) : get_item(id) [ item.depends ].flatten.compact.each { |dep| check dep } install item if force_install || item.local_command.nil? end
define(id) { |item| ... }
click to toggle source
Define a new item.
# File lib/bindep/context.rb, line 19 def define(id, &block) item = Item.new(id) yield item @registry[item.id] = item end
get_item(id)
click to toggle source
Gets an item from the registry.
# File lib/bindep/context.rb, line 44 def get_item(id) @registry[id.to_sym] || raise(Error, "Cannot find item '#{id.to_sym}' in context!") end
run(id, args = [], stdin = nil, raise_on_failure = true)
click to toggle source
Runs the specified command with the given arguments.
# File lib/bindep/context.rb, line 36 def run(id, args = [], stdin = nil, raise_on_failure = true) check id cmd_string = "#{get_item(id).local_command} #{[ args ].flatten.join(" ")}".strip Helpers.cmd cmd_string, stdin, raise_on_failure end
Private Instance Methods
error(message = nil)
click to toggle source
# File lib/bindep/context.rb, line 82 def error(message = nil) exception = Error.new message raise exception if silent_exceptions puts exception.to_s exit 1 end
install(item)
click to toggle source
# File lib/bindep/context.rb, line 72 def install(item) pre_install item Helpers.cmd_interactive item.install_command unless item.local_command true error "Installation for '#{item.id}' failed. Please install manually." end end
pre_install(item)
click to toggle source
# File lib/bindep/context.rb, line 49 def pre_install(item) if no_install error "Cannot find command for '#{item.id}' and installation is deactivated. "\ "Please install manually." end if item.install_command.nil? error "Cannot find installation instructions for '#{item.id}'. "\ "Please install manually." end unless no_confirm_before_install puts "[Bindep] Command '#{item.id}' is not installed. "\ "Do you want to run the following command? (y/n)" end puts "[Bindep] $ #{item.install_command}\n" unless no_confirm_before_install error "Aborting." unless STDIN.gets.downcase.strip == 'y' end end