Class: Hardhat::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/hardhat/installer.rb

Constant Summary collapse

COMMANDS =
[:install, :uninstall, :update]

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options={})
  unless options.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    = options[:sudo]
  @flags   = options[:flags]

  # dynamicly create a method for each COMMAND.
  metaclass = class << self; self; end
  COMMANDS.each do |cmd|
    if options.key? cmd
      instance_variable_set("@#{cmd}", options[cmd])
    else
      instance_variable_set("@#{cmd}", cmd)
    end
    metaclass.send(:define_method, cmd) do |dependency = nil, options = {}|
      if cmd != :update && dependency.nil?
        raise ArgumentError.new("requires a dependency")
      end
      run instance_variable_get("@#{cmd}"), dependency, options
    end
  end
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



4
5
6
# File 'lib/hardhat/installer.rb', line 4

def flags
  @flags
end

#programObject (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

Returns:

  • (Boolean)


35
36
37
# File 'lib/hardhat/installer.rb', line 35

def sudo?
  !!@sudo
end