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(&blk) ⇒ 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 |
# File 'lib/foreman/procfile.rb', line 34 def [](name) @entries.detect { |n,c| name == n }.last end |
#[]=(name, command) ⇒ Object
Create a Procfile
entry
43 44 45 46 |
# File 'lib/foreman/procfile.rb', line 43 def []=(name, command) delete name @entries << [name, command] end |
#delete(name) ⇒ Object
Remove a Procfile
entry
52 53 54 |
# File 'lib/foreman/procfile.rb', line 52 def delete(name) @entries.reject! { |n,c| name == n } end |
#entries(&blk) ⇒ Object
Yield each Procfile
entry in order
24 25 26 27 28 |
# File 'lib/foreman/procfile.rb', line 24 def entries(&blk) @entries.each do |(name, command)| yield name, command end end |
#load(filename) ⇒ Object
Load a Procfile from a file
60 61 62 |
# File 'lib/foreman/procfile.rb', line 60 def load(filename) @entries.replace parse(filename) end |
#save(filename) ⇒ Object
Save a Procfile to a file
68 69 70 71 72 |
# File 'lib/foreman/procfile.rb', line 68 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
76 77 78 79 80 |
# File 'lib/foreman/procfile.rb', line 76 def to_s @entries.map do |name, command| [ name, command ].join(": ") end.join("\n") end |