Class: Procodile::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/procodile/config.rb

Constant Summary collapse

COLORS =
[35, 31, 36, 32, 33, 34]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Config

Returns a new instance of Config.



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

def initialize(root)
  @root = root
  unless File.exist?(procfile_path)
    raise Error, "Procfile not found at #{procfile_path}"
  end

  FileUtils.mkdir_p(pid_root)
  FileUtils.mkdir_p(log_root)
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



10
11
12
# File 'lib/procodile/config.rb', line 10

def root
  @root
end

Instance Method Details

#app_nameObject



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

def app_name
  options['app_name'] || 'Procodile'
end

#log_rootObject



49
50
51
# File 'lib/procodile/config.rb', line 49

def log_root
  File.expand_path(options['log_root'] || 'log', @root)
end

#optionsObject



37
38
39
# File 'lib/procodile/config.rb', line 37

def options
  @options ||= File.exist?(options_path) ? YAML.load_file(options_path) : {}
end

#pid_rootObject



45
46
47
# File 'lib/procodile/config.rb', line 45

def pid_root
  File.expand_path(options['pid_root'] || 'pids', @root)
end

#process_listObject



33
34
35
# File 'lib/procodile/config.rb', line 33

def process_list
  @processes ||= YAML.load_file(procfile_path)
end

#process_optionsObject



41
42
43
# File 'lib/procodile/config.rb', line 41

def process_options
  @process_options ||= options['processes'] || {}
end

#processesObject



26
27
28
29
30
31
# File 'lib/procodile/config.rb', line 26

def processes
  process_list.each_with_index.each_with_object({}) do |((name, command), index), hash|
    options = {'log_color' => COLORS[index.divmod(COLORS.size)[1]]}.merge(process_options[name] || {})
    hash[name] = Process.new(self, name, command, options)
  end
end