Class: Foreman::Procfile
- Inherits:
-
Object
- Object
- Foreman::Procfile
- Defined in:
- lib/foreman/procfile.rb
Overview
Reads and writes Procfiles
A valid Procfile entry is captured by this regex:
/^([A-Za-z0-9_]+):\s*(.+)$/
All other lines are ignored.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Retrieve a
Procfile
command by name. -
#[]=(name, command) ⇒ Object
Create a
Procfile
entry. -
#delete(name) ⇒ Object
Remove a
Procfile
entry. -
#entries ⇒ Object
Yield each
Procfile
entry in order. -
#initialize(filename = nil) ⇒ Procfile
constructor
Initialize a Procfile.
-
#load(filename) ⇒ Object
Load a Procfile from a file.
-
#save(filename) ⇒ Object
Save a Procfile to a file.
-
#to_s ⇒ Object
Get the
Procfile
as aString
.
Constructor Details
#initialize(filename = nil) ⇒ Procfile
Initialize a Procfile
17 18 19 20 |
# File 'lib/foreman/procfile.rb', line 17 def initialize(filename=nil) @entries = [] load(filename) if filename end |
Instance Method Details
#[](name) ⇒ Object
Retrieve a Procfile
command by name
34 35 36 37 38 |
# File 'lib/foreman/procfile.rb', line 34 def [](name) if entry = @entries.detect { |n,c| name == n } entry.last end end |
#[]=(name, command) ⇒ Object
Create a Procfile
entry
45 46 47 48 |
# File 'lib/foreman/procfile.rb', line 45 def []=(name, command) delete name @entries << [name, command] end |
#delete(name) ⇒ Object
Remove a Procfile
entry
54 55 56 |
# File 'lib/foreman/procfile.rb', line 54 def delete(name) @entries.reject! { |n,c| name == n } end |
#entries ⇒ Object
Yield each Procfile
entry in order
24 25 26 27 28 |
# File 'lib/foreman/procfile.rb', line 24 def entries @entries.each do |(name, command)| yield name, command end end |
#load(filename) ⇒ Object
Load a Procfile from a file
62 63 64 |
# File 'lib/foreman/procfile.rb', line 62 def load(filename) @entries.replace parse(filename) end |
#save(filename) ⇒ Object
Save a Procfile to a file
70 71 72 73 74 |
# File 'lib/foreman/procfile.rb', line 70 def save(filename) File.open(filename, 'w') do |file| file.puts self.to_s end end |
#to_s ⇒ Object
Get the Procfile
as a String
78 79 80 81 82 |
# File 'lib/foreman/procfile.rb', line 78 def to_s @entries.map do |name, command| [ name, command ].join(": ") end.join("\n") end |