Class: Fate::Control

Inherits:
Object
  • Object
show all
Includes:
Harp
Defined in:
lib/fate.rb,
lib/fate/repl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manager, options = {}) ⇒ Control

Returns a new instance of Control.



27
28
29
30
31
32
33
34
# File 'lib/fate.rb', line 27

def initialize(manager, options={})
  @manager = manager
  @service = @manager.service
  @completions = @service.completions

  @spec = @service.specification
  @logger = @service.logger["Fate Control"]
end

Instance Attribute Details

#completionsObject (readonly)

Returns the value of attribute completions.



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

def completions
  @completions
end

#loggerObject (readonly)

Returns the value of attribute logger.



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

def logger
  @logger
end

#managerObject (readonly)

Returns the value of attribute manager.



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

def manager
  @manager
end

#serviceObject (readonly)

Returns the value of attribute service.



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

def service
  @service
end

Instance Method Details

#log(*args, &block) ⇒ Object



36
37
38
# File 'lib/fate.rb', line 36

def log(*args, &block)
  @logger.log(*args, &block)
end

#restart(*command_strings) ⇒ Object



52
53
54
55
# File 'lib/fate.rb', line 52

def restart(*command_strings)
  stop(*command_strings)
  start(*command_strings)
end

#run(*command_strings) ⇒ Object

Run only the processes specified by the arguments. Any existing processes outside this set will be stopped.



59
60
61
# File 'lib/fate.rb', line 59

def run(*command_strings)
  manager.run(command_strings)
end

#runningObject



63
64
65
# File 'lib/fate.rb', line 63

def running
  manager.running
end

#start(*command_strings) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/fate.rb', line 40

def start(*command_strings)
  if manager.start(command_strings)
    logger.green "All processes are running."
  else
    logger.error "Failed to start."
  end
end

#stop(*command_strings) ⇒ Object



48
49
50
# File 'lib/fate.rb', line 48

def stop(*command_strings)
  manager.stop(command_strings)
end

#system(command) ⇒ Object

ad hoc shell out, with rescuing because of some apparent bugs in MRI 1.8.7’s ability to cope with unusual exit codes.



69
70
71
72
73
74
75
# File 'lib/fate.rb', line 69

def system(command)
  begin
    Kernel.system command
  rescue => error
    puts "Exception raised when executing '#{command}': #{error.inspect}"
  end
end