Class: Kender::Command

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

Overview

This class abstracts the shell commands we use

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#successObject (readonly)

Returns the value of attribute success.



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

def success
  @success
end

Class Method Details

.allObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kender/command.rb', line 42

def all
  @all ||= begin
    all_commands = commands.select(&:available?)
    # move rspec and cucumber to last places so faster tools run first
    if command = all_commands.find{ |command| command.name == :rspec }
      all_commands.delete_if{ |command| command.name == :rspec }.push(command)
    end
     if command = all_commands.find{ |command| command.name == :cucumber }
      all_commands.delete_if{ |command| command.name == :cucumber }.push(command)
    end
    all_commands
  end
end

.all_namesObject



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

def all_names
  all.map(&:name)
end

.all_success?Boolean

Returns:

  • (Boolean)


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

def all_success?
  all.inject(true) {|all_result, command_result| all_result && command_result }
end

.commandsObject



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

def commands
  @commands ||= []
end

.inherited(klass) ⇒ Object



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

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

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


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

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

#executeObject



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

def execute
  @success = run.success?
end

#nameObject



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

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

#runObject

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



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

def run
  system(command)
  $?
end