class Divide::Extractor
Constants
- DEFAULT_ENV
Public Class Methods
new(flags = [], options = {})
click to toggle source
# File lib/divide/extractor.rb, line 7 def initialize(flags = [], options = {}) @flags = flags @options = options overwrite_env_variables overwrite_flags escape_double_quotes end
Public Instance Methods
env_content()
click to toggle source
# File lib/divide/extractor.rb, line 20 def env_content @env_content ||= File.read("#{@options[:from]}/.env") rescue '' end
env_variables()
click to toggle source
# File lib/divide/extractor.rb, line 46 def env_variables @env_variables ||= begin env_content.split(/\n/).inject({}) do |memo, line| variable, value = line.split(/=/) next {} if variable == nil || variable.chars.first == '#' memo.merge variable => value end end end
escape_double_quotes()
click to toggle source
# File lib/divide/extractor.rb, line 37 def escape_double_quotes procfile_content.gsub!('"', '\"') end
extract_processes!()
click to toggle source
# File lib/divide/extractor.rb, line 41 def extract_processes! return nil if procfile_content.empty? YAML.load(procfile_content) end
overwrite_env_variables()
click to toggle source
# File lib/divide/extractor.rb, line 56 def overwrite_env_variables DEFAULT_ENV.merge(env_variables).each do |variable, value| procfile_content.gsub!("$#{variable}", value) end end
overwrite_flags()
click to toggle source
# File lib/divide/extractor.rb, line 24 def overwrite_flags @flags.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()
click to toggle source
# File lib/divide/extractor.rb, line 16 def procfile_content @procfile_content ||= File.read("#{@options[:from]}/Procfile") rescue '' end