Class: Procodile::Config
- Inherits:
-
Object
- Object
- Procodile::Config
- Defined in:
- lib/procodile/config.rb
Constant Summary collapse
- COLORS =
[35, 31, 36, 32, 33, 34]
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #app_name ⇒ Object
-
#initialize(root) ⇒ Config
constructor
A new instance of Config.
- #log_root ⇒ Object
- #options ⇒ Object
- #pid_root ⇒ Object
- #process_list ⇒ Object
- #process_options ⇒ Object
- #processes ⇒ Object
- #reload ⇒ Object
- #sock_path ⇒ Object
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
#root ⇒ Object (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_name ⇒ Object
49 50 51 |
# File 'lib/procodile/config.rb', line 49 def app_name @app_name ||= ['app_name'] || 'Procodile' end |
#log_root ⇒ Object
76 77 78 |
# File 'lib/procodile/config.rb', line 76 def log_root @log_root ||= File.(['log_root'] || 'log', @root) end |
#options ⇒ Object
64 65 66 |
# File 'lib/procodile/config.rb', line 64 def @options ||= File.exist?() ? YAML.load_file() : {} end |
#pid_root ⇒ Object
72 73 74 |
# File 'lib/procodile/config.rb', line 72 def pid_root @pid_root ||= File.(['pid_root'] || 'pids', @root) end |
#process_list ⇒ Object
60 61 62 |
# File 'lib/procodile/config.rb', line 60 def process_list @process_list ||= YAML.load_file(procfile_path) end |
#process_options ⇒ Object
68 69 70 |
# File 'lib/procodile/config.rb', line 68 def @process_options ||= ['processes'] || {} end |
#processes ⇒ Object
53 54 55 56 57 58 |
# File 'lib/procodile/config.rb', line 53 def processes @processes ||= process_list.each_with_index.each_with_object({}) do |((name, command), index), hash| hash[name] = Process.new(self, name, command, [name] || {}) hash[name].log_color = COLORS[index.divmod(COLORS.size)[1]] end end |
#reload ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/procodile/config.rb', line 22 def reload @process_list = nil @options = nil @process_options = nil process_list.each do |name, command| if process = @processes[name] # This command is already in our list. Add it. if process.command != command process.command = command Procodile.log nil, 'system', "#{name} command has changed. Updated." end if [name].is_a?(Hash) process. = [name] else process. = {} end else Procodile.log nil, 'system', "#{name} has been added to the Procfile. Adding it." @processes[name] = Process.new(self, name, command, [name] || {}) @processes[name].log_color = COLORS[@processes.size.divmod(COLORS.size)[1]] end end end |
#sock_path ⇒ Object
80 81 82 |
# File 'lib/procodile/config.rb', line 80 def sock_path File.join(pid_root, 'supervisor.sock') end |