Class: Foreman::Procfile

### Home Classes Methods

### In Files

- lib/foreman/procfile.rb

### Parent

Object

### Methods

- ::new
- #[]
- #[]=
- #delete
- #entries
- #load
- #save
- #to_s

### Class/Module Index

Quicksearch

- Foreman
- Foreman::AppDoesNotExist
- Foreman::CLI
- Foreman::Distribution
- Foreman::Engine
- Foreman::Engine::CLI
- Foreman::Engine::CLI::Color
- Foreman::Export
- Foreman::Export::Base
- Foreman::Export::Bluepill
- Foreman::Export::Exception
- Foreman::Export::Inittab
- Foreman::Export::Launchd
- Foreman::Export::Runit
- Foreman::Export::Supervisord
- Foreman::Export::Upstart
- Foreman::Helpers
- Foreman::Process
- Foreman::Procfile

No matching classes.

# Foreman::Procfile

Reads and writes Procfiles

A valid Procfile entry is captured by this regex:

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

All other lines are ignored.

### Public Class Methods

new(filename=nil) click to toggle source

Initialize a Procfile

@param [String] filename (nil) An optional filename to read from

    # File lib/foreman/procfile.rb, line 17
    def initialize(filename=nil)
      @entries = []
      load(filename) if filename
    end

### Public Instance Methods

[](name) click to toggle source

Retrieve a `Procfile` command by name

@param [String] name The name of the Procfile entry to retrieve

    # File lib/foreman/procfile.rb, line 34
    def [](name)
      @entries.detect { |n,c| name == n }.last
    end

[]=(name, command) click to toggle source

Create a `Procfile` entry

@param [String] name The name of the `Procfile` entry to create @param [String] command The command of the `Procfile` entry to create

    # File lib/foreman/procfile.rb, line 43
    def []=(name, command)
      delete name
      @entries << [name, command]
    end

delete(name) click to toggle source

Remove a `Procfile` entry

@param [String] name The name of the `Procfile` entry to remove

    # File lib/foreman/procfile.rb, line 52
    def delete(name)
      @entries.reject! { |n,c| name == n }
    end

entries(&blk) click to toggle source

Yield each `Procfile` entry in order

    # File lib/foreman/procfile.rb, line 24
    def entries(&blk)
      @entries.each do |(name, command)|
        yield name, command
      end
    end

load(filename) click to toggle source

Load a Procfile from a file

@param [String] filename The filename of the `Procfile` to load

    # File lib/foreman/procfile.rb, line 60
    def load(filename)
      @entries.replace parse(filename)
    end

save(filename) click to toggle source

Save a Procfile to a file

@param [String] filename Save the `Procfile` to this file

    # 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() click to toggle source

Get the `Procfile` as a `String`

    # File lib/foreman/procfile.rb, line 76
    def to_s
      @entries.map do |name, command|
        [ name, command ].join(": ")
      end.join("\n")
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.