Class: Hardhat::Installer
- Inherits:
-
Object
- Object
- Hardhat::Installer
- Defined in:
- lib/hardhat/installer.rb
Constant Summary collapse
- COMMANDS =
[:install, :uninstall, :update]
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#program ⇒ Object
readonly
Returns the value of attribute program.
Instance Method Summary collapse
-
#initialize(program, options = {}) ⇒ Installer
constructor
A new instance of Installer.
-
#sudo? ⇒ Boolean
Always returns a valid bolean.
Constructor Details
#initialize(program, options = {}) ⇒ Installer
Returns a new instance of Installer.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/hardhat/installer.rb', line 6 def initialize(program, ={}) unless .is_a? Hash raise ArgumentError.new "options should be a hash" end unless Hardhat::System.has? program raise ArgumentError.new "program not found: #{program}" end @program = program @sudo = [:sudo] @flags = [:flags] # dynamicly create a method for each COMMAND. = class << self; self; end COMMANDS.each do |cmd| if .key? cmd instance_variable_set("@#{cmd}", [cmd]) else instance_variable_set("@#{cmd}", cmd) end .send(:define_method, cmd) do |dependency = nil, = {}| if cmd != :update && dependency.nil? raise ArgumentError.new("requires a dependency") end run instance_variable_get("@#{cmd}"), dependency, end end end |
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
4 5 6 |
# File 'lib/hardhat/installer.rb', line 4 def flags @flags end |
#program ⇒ Object (readonly)
Returns the value of attribute program.
4 5 6 |
# File 'lib/hardhat/installer.rb', line 4 def program @program end |
Instance Method Details
#sudo? ⇒ Boolean
Always returns a valid bolean
35 36 37 |
# File 'lib/hardhat/installer.rb', line 35 def sudo? !!@sudo end |