Class: Divide::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/divide/extractor.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = []) ⇒ Extractor

Returns a new instance of Extractor.



4
5
6
7
8
9
10
# File 'lib/divide/extractor.rb', line 4

def initialize(options=[])
  @procfile_content = File.read('./Procfile') rescue ''
  @options = options

  overwrite_options
  overwrite_port
end

Instance Method Details

#extract_processes!Object



30
31
32
33
# File 'lib/divide/extractor.rb', line 30

def extract_processes!
  return nil if @procfile_content.empty?
  YAML.load(@procfile_content)
end

#overwrite_optionsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/divide/extractor.rb', line 12

def overwrite_options
  splitted_procfile = @procfile_content.split(/\s/)

  @options.each do |option|
    key = option[0]
    value = option[1]

    key_index = splitted_procfile.index(key)
    value_to_overwrite = splitted_procfile[key_index + 1]

    @procfile_content.sub!(value_to_overwrite, value)
  end
end

#overwrite_portObject



26
27
28
# File 'lib/divide/extractor.rb', line 26

def overwrite_port
  @procfile_content.sub!('$PORT', ENV['PORT'] || '5000')
end