Class: Divide::Extractor
- Inherits:
-
Object
- Object
- Divide::Extractor
- Defined in:
- lib/divide/extractor.rb
Constant Summary collapse
- DEFAULT_ENV =
{ 'PORT' => '5000' }.merge(ENV)
Instance Method Summary collapse
- #env_content ⇒ Object
- #env_variables ⇒ Object
- #escape_double_quotes ⇒ Object
- #extract_processes! ⇒ Object
-
#initialize(options = []) ⇒ Extractor
constructor
A new instance of Extractor.
- #overwrite_env_variables ⇒ Object
- #overwrite_options ⇒ Object
- #procfile_content ⇒ Object
Constructor Details
#initialize(options = []) ⇒ Extractor
Returns a new instance of Extractor.
7 8 9 10 11 12 13 |
# File 'lib/divide/extractor.rb', line 7 def initialize(=[]) = overwrite_env_variables escape_double_quotes end |
Instance Method Details
#env_content ⇒ Object
19 20 21 |
# File 'lib/divide/extractor.rb', line 19 def env_content @env_content ||= File.read('./.env') rescue '' end |
#env_variables ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/divide/extractor.rb', line 48 def env_variables @env_variables ||= begin env_content.split(/\n/).inject({}) do |memo, line| variable, value = line.split(/=/) memo.merge variable => value end end end |
#escape_double_quotes ⇒ Object
39 40 41 |
# File 'lib/divide/extractor.rb', line 39 def escape_double_quotes procfile_content.gsub!('"', '\"') end |
#extract_processes! ⇒ Object
43 44 45 46 |
# File 'lib/divide/extractor.rb', line 43 def extract_processes! return nil if procfile_content.empty? YAML.load(procfile_content) end |
#overwrite_env_variables ⇒ Object
57 58 59 60 61 |
# File 'lib/divide/extractor.rb', line 57 def overwrite_env_variables DEFAULT_ENV.merge(env_variables).each do |variable, value| procfile_content.gsub!("$#{variable}", value) end end |
#overwrite_options ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/divide/extractor.rb', line 23 def splitted_content = procfile_content.split(/\s/) .each do |option| next if option.length < 2 key = option[0] value = option[1] if key_index = splitted_content.index(key) value_to_overwrite = splitted_content[key_index + 1] procfile_content.sub!(value_to_overwrite, value) end end end |
#procfile_content ⇒ Object
15 16 17 |
# File 'lib/divide/extractor.rb', line 15 def procfile_content @procfile_content ||= File.read('./Procfile') rescue '' end |