Class: EnvExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/dotenv/env_extractor.rb

Instance Method Summary collapse

Instance Method Details

#extensionsObject



2
3
4
# 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 = '*') ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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