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(=[]) @options = 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
45 46 47 48 49 50 51 52 |
# File 'lib/divide/extractor.rb', line 45 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
36 37 38 |
# File 'lib/divide/extractor.rb', line 36 def escape_double_quotes procfile_content.gsub!('"', '\"') end |
#extract_processes! ⇒ Object
40 41 42 43 |
# File 'lib/divide/extractor.rb', line 40 def extract_processes! return nil if procfile_content.empty? YAML.load(procfile_content) end |
#overwrite_env_variables ⇒ Object
54 55 56 57 58 |
# File 'lib/divide/extractor.rb', line 54 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 |
# File 'lib/divide/extractor.rb', line 23 def @options.each do |option| next if option.length < 2 key = option[0] value = option[1] procfile_content.scan(/\s?#{key}\s(\S+)/).each do |value_to_overwrite| procfile_content.gsub!(value_to_overwrite[0], 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 |