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 Method Summary collapse
- #app_name ⇒ Object
- #console_command ⇒ Object
- #environment_variables ⇒ Object
-
#initialize(root, procfile = nil) ⇒ Config
constructor
A new instance of Config.
- #local_options ⇒ Object
- #local_options_path ⇒ Object
- #local_process_options ⇒ Object
- #log_path ⇒ Object
- #log_root ⇒ Object
- #options ⇒ Object
- #options_for_process(name) ⇒ Object
- #options_path ⇒ Object
- #pid_root ⇒ Object
- #process_list ⇒ Object
- #process_options ⇒ Object
- #processes ⇒ Object
- #procfile_path ⇒ Object
- #reload ⇒ Object
- #root ⇒ Object
- #sock_path ⇒ Object
- #supervisor_pid_path ⇒ Object
- #user ⇒ Object
Constructor Details
#initialize(root, procfile = nil) ⇒ Config
Returns a new instance of Config.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/procodile/config.rb', line 11 def initialize(root, procfile = nil) @root = root @procfile_path = procfile unless File.file?(procfile_path) raise Error, "Procfile not found at #{procfile_path}" end # We need to check to see if the local or options # configuration will override the root that we've been given. # If they do, we can throw away any reference to the one that the # configuration was initialized with and start using that immediately. if new_root = (['root'] || ['root']) @root = new_root end FileUtils.mkdir_p(pid_root) @processes = process_list.each_with_index.each_with_object({}) do |((name, command), index), hash| hash[name] = create_process(name, command, COLORS[index.divmod(COLORS.size)[1]]) end end |
Instance Method Details
#app_name ⇒ Object
75 76 77 |
# File 'lib/procodile/config.rb', line 75 def app_name @app_name ||= ['app_name'] || ['app_name'] || 'Procodile' end |
#console_command ⇒ Object
79 80 81 |
# File 'lib/procodile/config.rb', line 79 def console_command ['console_command'] || ['console_command'] end |
#environment_variables ⇒ Object
111 112 113 |
# File 'lib/procodile/config.rb', line 111 def environment_variables (['env'] || {}).merge(['env'] || {}) end |
#local_options ⇒ Object
99 100 101 |
# File 'lib/procodile/config.rb', line 99 def @local_options ||= end |
#local_options_path ⇒ Object
154 155 156 |
# File 'lib/procodile/config.rb', line 154 def procfile_path + ".local" end |
#local_process_options ⇒ Object
103 104 105 |
# File 'lib/procodile/config.rb', line 103 def @local_process_options ||= ['processes'] || {} end |
#log_path ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/procodile/config.rb', line 123 def log_path log_path = ['log_path'] || ['log_path'] if log_path File.(log_path, self.root) elsif log_path.nil? && self.log_root File.join(self.log_root, 'procodile.log') else File.("procodile.log", self.root) end end |
#log_root ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/procodile/config.rb', line 134 def log_root if log_root = (['log_root'] || ['log_root']) File.(log_root, self.root) else nil end end |
#options ⇒ Object
91 92 93 |
# File 'lib/procodile/config.rb', line 91 def @options ||= end |
#options_for_process(name) ⇒ Object
107 108 109 |
# File 'lib/procodile/config.rb', line 107 def (name) ([name] || {}).merge([name] || {}) end |
#options_path ⇒ Object
150 151 152 |
# File 'lib/procodile/config.rb', line 150 def procfile_path + ".options" end |
#pid_root ⇒ Object
115 116 117 |
# File 'lib/procodile/config.rb', line 115 def pid_root File.(['pid_root'] || ['pid_root'] || 'pids', self.root) end |
#process_list ⇒ Object
87 88 89 |
# File 'lib/procodile/config.rb', line 87 def process_list @process_list ||= load_process_list_from_file end |
#process_options ⇒ Object
95 96 97 |
# File 'lib/procodile/config.rb', line 95 def @process_options ||= ['processes'] || {} end |
#processes ⇒ Object
83 84 85 |
# File 'lib/procodile/config.rb', line 83 def processes @processes ||= {} end |
#procfile_path ⇒ Object
146 147 148 |
# File 'lib/procodile/config.rb', line 146 def procfile_path @procfile_path || File.join(self.root, 'Procfile') end |
#reload ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/procodile/config.rb', line 33 def reload @process_list = nil @options = nil @process_options = nil @local_options = nil @local_process_options = nil if @processes process_list.each do |name, command| if process = @processes[name] process.removed = false # 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 process. = (name) else Procodile.log nil, 'system', "#{name} has been added to the Procfile. Adding it." @processes[name] = create_process(name, command, COLORS[@processes.size.divmod(COLORS.size)[1]]) end end removed_processes = @processes.keys - process_list.keys removed_processes.each do |process_name| if p = @processes[process_name] p.removed = true @processes.delete(process_name) Procodile.log nil, 'system', "#{process_name} has been removed to the Procfile. It will be removed when it is stopped." end end end end |
#root ⇒ Object
67 68 69 |
# File 'lib/procodile/config.rb', line 67 def root @root end |
#sock_path ⇒ Object
142 143 144 |
# File 'lib/procodile/config.rb', line 142 def sock_path File.join(pid_root, 'procodile.sock') end |
#supervisor_pid_path ⇒ Object
119 120 121 |
# File 'lib/procodile/config.rb', line 119 def supervisor_pid_path File.join(pid_root, 'procodile.pid') end |
#user ⇒ Object
71 72 73 |
# File 'lib/procodile/config.rb', line 71 def user ['user'] || ['user'] end |