Class: Islo::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/islo/command.rb

Overview

Generic command execution

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, title: nil, wd: nil) ⇒ Command

Returns a new instance of Command.



11
12
13
14
15
16
# File 'lib/islo/command.rb', line 11

def initialize(args, title: nil, wd: nil)
  @command = args.shift
  @args = args
  @title = title unless title.nil? || title.empty?
  @wd = Pathname.new(wd || Dir.pwd)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



9
10
11
# File 'lib/islo/command.rb', line 9

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



9
10
11
# File 'lib/islo/command.rb', line 9

def command
  @command
end

#titleObject (readonly)

Returns the value of attribute title.



8
9
10
# File 'lib/islo/command.rb', line 8

def title
  @title
end

#wdObject (readonly)

Returns the value of attribute wd.



8
9
10
# File 'lib/islo/command.rb', line 8

def wd
  @wd
end

Instance Method Details

#execObject



22
23
24
25
26
27
# File 'lib/islo/command.rb', line 22

def exec
  Dir.chdir(wd.to_s)
  Kernel.exec(*args_for_exec)
rescue SystemCallError => e
  raise Command::Error, e.message
end

#title?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/islo/command.rb', line 18

def title?
  !title.nil?
end