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
-
#environment ⇒ Object
readonly
Returns the value of attribute environment.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
- #app_name ⇒ Object
- #environment_variables ⇒ Object
-
#initialize(root, environment, procfile = nil) ⇒ Config
constructor
A new instance of Config.
- #local_options ⇒ Object
- #local_process_options ⇒ Object
- #log_path ⇒ Object
- #options ⇒ Object
- #options_for_process(name) ⇒ Object
- #pid_root ⇒ Object
- #process_list ⇒ Object
- #process_options ⇒ Object
- #processes ⇒ Object
- #reload ⇒ Object
- #sock_path ⇒ Object
Constructor Details
#initialize(root, environment, procfile = nil) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/procodile/config.rb', line 13 def initialize(root, environment, procfile = nil) @root = root @environment = environment || 'production' @procfile = procfile unless File.exist?(procfile_path) raise Error, "Procfile not found at #{procfile_path}" 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 Attribute Details
#environment ⇒ Object (readonly)
Returns the value of attribute environment.
11 12 13 |
# File 'lib/procodile/config.rb', line 11 def environment @environment end |
#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
61 62 63 |
# File 'lib/procodile/config.rb', line 61 def app_name @app_name ||= fetch(['app_name']) || fetch(['app_name']) || 'Procodile' end |
#environment_variables ⇒ Object
93 94 95 |
# File 'lib/procodile/config.rb', line 93 def environment_variables fetch_hash_values(['env'] || {}).merge(fetch_hash_values(['env'] || {})) end |
#local_options ⇒ Object
81 82 83 |
# File 'lib/procodile/config.rb', line 81 def ||= File.exist?() ? YAML.load_file() : {} end |
#local_process_options ⇒ Object
85 86 87 |
# File 'lib/procodile/config.rb', line 85 def ||= ['processes'] || {} end |
#log_path ⇒ Object
101 102 103 |
# File 'lib/procodile/config.rb', line 101 def log_path @log_path ||= File.(fetch(['log_path']) || fetch(['log_path']) || 'procodile.log', @root) end |
#options ⇒ Object
73 74 75 |
# File 'lib/procodile/config.rb', line 73 def ||= File.exist?() ? YAML.load_file() : {} end |
#options_for_process(name) ⇒ Object
89 90 91 |
# File 'lib/procodile/config.rb', line 89 def (name) ([name] || {}).merge([name] || {}) end |
#pid_root ⇒ Object
97 98 99 |
# File 'lib/procodile/config.rb', line 97 def pid_root @pid_root ||= File.(fetch(['pid_root']) || fetch(['pid_root']) || 'pids', @root) end |
#process_list ⇒ Object
69 70 71 |
# File 'lib/procodile/config.rb', line 69 def process_list @process_list ||= YAML.load_file(procfile_path) || {} end |
#process_options ⇒ Object
77 78 79 |
# File 'lib/procodile/config.rb', line 77 def ||= ['processes'] || {} end |
#processes ⇒ Object
65 66 67 |
# File 'lib/procodile/config.rb', line 65 def processes @processes ||= {} end |
#reload ⇒ Object
27 28 29 30 31 32 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 |
# File 'lib/procodile/config.rb', line 27 def reload @process_list = nil = nil = nil = nil = 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 |
#sock_path ⇒ Object
105 106 107 |
# File 'lib/procodile/config.rb', line 105 def sock_path File.join(pid_root, 'procodile.sock') end |