Module: ProcMan

Defined in:
lib/proc_man.rb,
lib/proc_man/process.rb,
lib/proc_man/procfile.rb,
lib/proc_man/constraint.rb

Defined Under Namespace

Classes: Constraint, Error, Process, Procfile

Constant Summary collapse

VERSION =
'1.9.1'

Class Method Summary collapse

Class Method Details

.initObject

Create a new Procfile template in the current directory root



47
48
49
50
51
52
53
54
55
56
# File 'lib/proc_man.rb', line 47

def init
  path = File.expand_path('./Procfile')
  if File.file?(path)
    raise Error, "Procfile already exists at #{path}"
  else
    template_path = File.expand_path('../../Procfile.template', __FILE__)
    File.open(path, 'w') { |f| f.write(File.read(template_path)) }
    puts "\e[32mProcfile created at #{path}"
  end
end

.load_procfile(path) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/proc_man.rb', line 13

def load_procfile(path)
  if File.file?(path)
    ProcMan::Procfile.class_eval(File.read(path))
    puts "\e[35mProcfile loaded from #{path}\e[0m"
  else
    raise Error, "Procfile not found at #{path}"
  end
end

.processesObject



22
23
24
# File 'lib/proc_man.rb', line 22

def processes
  @processes ||= Array.new
end

.run(method, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/proc_man.rb', line 26

def run(method, options = {})
  load_procfile(options[:procfile] || File.expand_path('./Procfile'))
  if method.nil?
    raise Error, "Command to execute was not specified. For example, pass 'start' to start processes."
  else
    ENV["PROCMAN_ENABLED"] = 'yes'
    for process in self.processes
      process.options = options
      if process.defined_method?(method)
        if process.execute?
          puts "----> \e[33m#{method.capitalize}ing #{process.name}\e[0m"
          process.send(method)
        end
      else
        puts "\e[31mThe #{process.name} process does not implement a '#{method}' method\e[0m"
      end
    end
  end
end