Class: Bindep::Context
- Inherits:
-
Object
- Object
- Bindep::Context
- Defined in:
- lib/bindep/context.rb
Instance Attribute Summary collapse
-
#no_confirm_before_install ⇒ Object
Returns the value of attribute no_confirm_before_install.
-
#no_install ⇒ Object
Returns the value of attribute no_install.
-
#silent_exceptions ⇒ Object
Returns the value of attribute silent_exceptions.
Instance Method Summary collapse
-
#check(id, force_install = false, &block) ⇒ Object
Check if a given item is installed, can also define item beforehand if block is given.
-
#define(id) {|item| ... } ⇒ Object
Define a new item.
-
#get_item(id) ⇒ Object
Gets an item from the registry.
-
#initialize ⇒ Context
constructor
Create a new Bindep context with its own options and item registry.
-
#run(id, args = [], stdin = nil, raise_on_failure = true) ⇒ Object
Runs the specified command with the given arguments.
Constructor Details
#initialize ⇒ Context
Create a new Bindep context with its own options and item registry.
6 7 8 9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#no_confirm_before_install ⇒ Object
Returns the value of attribute no_confirm_before_install.
3 4 5 |
# File 'lib/bindep/context.rb', line 3 def no_confirm_before_install @no_confirm_before_install end |
#no_install ⇒ Object
Returns the value of attribute no_install.
3 4 5 |
# File 'lib/bindep/context.rb', line 3 def no_install @no_install end |
#silent_exceptions ⇒ Object
Returns the value of attribute silent_exceptions.
3 4 5 |
# File 'lib/bindep/context.rb', line 3 def silent_exceptions @silent_exceptions end |
Instance Method Details
#check(id, force_install = false, &block) ⇒ Object
Check if a given item is installed, can also define item beforehand if block is given.
27 28 29 30 31 32 33 |
# 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| ... } ⇒ Object
Define a new item.
19 20 21 22 23 24 |
# 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) ⇒ Object
Gets an item from the registry.
44 45 46 |
# 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) ⇒ Object
Runs the specified command with the given arguments.
36 37 38 39 40 41 |
# 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 |