Class: Battlestation::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/battlestation/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Task

Returns a new instance of Task.



6
7
8
9
10
11
# File 'lib/battlestation/task.rb', line 6

def initialize(name, &block)
  @name = name
  @operations = []

  instance_eval &block if block_given?
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/battlestation/task.rb', line 3

def name
  @name
end

#operationsObject

Returns the value of attribute operations.



4
5
6
# File 'lib/battlestation/task.rb', line 4

def operations
  @operations
end

Instance Method Details

#executable(filename, opts = {}) ⇒ Object

Check if an executable exists



18
19
20
# File 'lib/battlestation/task.rb', line 18

def executable(filename, opts = {})
  operations << Battlestation::Operations::ExecutableCheck.new(filename, opts)
end

#executeObject

Execute this dependency



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/battlestation/task.rb', line 38

def execute
  Battlestation.ui.notice("Nothing defined for #{task.name}") and return if operations.empty?

  statuses = []
  # Report successes and failures
  operations.each do |operation|
    status = operation.status
    statuses << status

    Battlestation.ui.send(status[:status], status[:msg])

    if status[:resolution]
      Battlestation.ui.todo(">> " + status[:resolution])
    end

    # Exit if this task failed. No point continuing
    if status[:status] == :fail
      Battlestation.ui.fail(">> Please resolve the failures above and re-run `battlestation`")
      exit 1
    end
  end
end

#file_exists(filename, opts = {}) ⇒ Object

Check if a file exists



23
24
25
# File 'lib/battlestation/task.rb', line 23

def file_exists(filename, opts = {})
  operations << Battlestation::Operations::FileExistsCheck.new(filename, opts)
end

#process(identifier, opts = {}) ⇒ Object

Check if a process is running



28
29
30
# File 'lib/battlestation/task.rb', line 28

def process(identifier, opts = {})
  operations << Battlestation::Operations::ProcessCheck.new(identifier, opts)
end

#run(cmd, opts = {}) ⇒ Object

Run the specified command, fail if unsucessful



33
34
35
# File 'lib/battlestation/task.rb', line 33

def run(cmd, opts = {})
  operations << Battlestation::Operations::Runner.new(cmd, opts)
end

#titleObject



13
14
15
# File 'lib/battlestation/task.rb', line 13

def title
  "Manning #{name}"
end