class EnvExtractor
Public Instance Methods
extensions()
click to toggle source
# File lib/capistrano/dotenv/env_extractor.rb, line 2 def extensions %w(ru thor rake rb yml ruby yaml erb builder markerb haml) end
extract_env_vars(globs = '*')
click to toggle source
# File lib/capistrano/dotenv/env_extractor.rb, line 6 def extract_env_vars(globs = '*') results = Hash.new { |hash, key| hash[key] = [] } Array(globs).each do |glob| Dir.glob(glob).each do |item| next if File.basename(item)[0] == ?. if File.directory?(item) results.merge!(extract_env_vars("#{item}/*")) else next unless extensions.detect {|ext| File.extname(item)[ext] } File.readlines(item).each_with_index do |line, ix| capture_variables(line).each do |variable| results[variable] << { :path => item, :line => ix.succ } end end end end end results end
Private Instance Methods
capture_variables(line)
click to toggle source
# File lib/capistrano/dotenv/env_extractor.rb, line 31 def capture_variables(line) line.scan(/ENV(?:\[|\.fetch\()['"]([^'"]+)['"]/).flatten end