Class: Invoker::Parsers::Procfile
- Inherits:
-
Object
- Object
- Invoker::Parsers::Procfile
- Defined in:
- lib/invoker/parsers/procfile.rb
Overview
rip off from foreman
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
9 10 11 12 |
# File 'lib/invoker/parsers/procfile.rb', line 9 def initialize(filename=nil) @entries = [] load(filename) if filename end |
Instance Method Details
#[](name) ⇒ Object
Retrieve a Procfile
command by name
27 28 29 |
# File 'lib/invoker/parsers/procfile.rb', line 27 def [](name) @entries.detect { |n,c| name == n }.last end |
#[]=(name, command) ⇒ Object
Create a Procfile
entry
36 37 38 39 |
# File 'lib/invoker/parsers/procfile.rb', line 36 def []=(name, command) delete name @entries << [name, command] end |
#delete(name) ⇒ Object
Remove a Procfile
entry
45 46 47 |
# File 'lib/invoker/parsers/procfile.rb', line 45 def delete(name) @entries.reject! { |n,c| name == n } end |
#entries ⇒ Object
Yield each Procfile
entry in order
16 17 18 19 20 21 |
# File 'lib/invoker/parsers/procfile.rb', line 16 def entries return @entries unless block_given? @entries.each do |(name, command)| yield name, command end end |
#load(filename) ⇒ Object
Load a Procfile from a file
53 54 55 |
# File 'lib/invoker/parsers/procfile.rb', line 53 def load(filename) @entries.replace parse(filename) end |
#save(filename) ⇒ Object
Save a Procfile to a file
61 62 63 64 65 |
# File 'lib/invoker/parsers/procfile.rb', line 61 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
69 70 71 72 73 |
# File 'lib/invoker/parsers/procfile.rb', line 69 def to_s @entries.map do |name, command| [ name, command ].join(": ") end.join("\n") end |