Class: Kender::Command

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

Overview

This class abstracts the shell commands we use

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.allObject



37
38
39
# File 'lib/kender/command.rb', line 37

def all
  @all ||= commands.select(&:available?)
end

.all_namesObject



33
34
35
# File 'lib/kender/command.rb', line 33

def all_names
  all.map(&:name)
end

.commandsObject



25
26
27
# File 'lib/kender/command.rb', line 25

def commands
  @commands ||= []
end

.inherited(klass) ⇒ Object



29
30
31
# File 'lib/kender/command.rb', line 29

def inherited(klass)
  commands << klass.new
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


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

def available?
  abort "Command failed: #{name}, availability status undefined."
end

#executeObject



13
14
15
# File 'lib/kender/command.rb', line 13

def execute
  abort "Command failed: #{command}" unless run.success?
end

#nameObject



5
6
7
# File 'lib/kender/command.rb', line 5

def name
  self.class.name.split("::").last.downcase.to_sym
end

#runObject

TODO: system reload all the gems again, avoid this.



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

def run
  system(command)
  $?
end