Class: Foreman::Procfile

Inherits:
Object
  • Object
show all
Defined in:
lib/foreman/procfile.rb

Overview

A valid Procfile entry is captured by this regex. All other lines are ignored.

/^([A-Za-z0-9_]+):s*(.+)$/

$1 = name $2 = command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ Procfile

Returns a new instance of Procfile.



16
17
18
19
# File 'lib/foreman/procfile.rb', line 16

def initialize(filename=nil)
  @entries = []
  load(filename) if filename
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



14
15
16
# File 'lib/foreman/procfile.rb', line 14

def entries
  @entries
end

Instance Method Details

#<<(entry) ⇒ Object



42
43
44
45
# File 'lib/foreman/procfile.rb', line 42

def <<(entry)
  entries << Foreman::ProcfileEntry.new(*entry)
  self
end

#[](name) ⇒ Object



21
22
23
# File 'lib/foreman/procfile.rb', line 21

def [](name)
  entries.detect { |entry| entry.name == name }
end

#load(filename) ⇒ Object



29
30
31
32
# File 'lib/foreman/procfile.rb', line 29

def load(filename)
  entries.clear
  parse_procfile(filename)
end

#process_namesObject



25
26
27
# File 'lib/foreman/procfile.rb', line 25

def process_names
  entries.map(&:name)
end

#write(filename) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/foreman/procfile.rb', line 34

def write(filename)
  File.open(filename, 'w') do |io|
    entries.each do |ent|
      io.puts(ent)
    end
  end
end