Class: Depec::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/depec/analyzer.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir, config) ⇒ Analyzer

Returns a new instance of Analyzer.

Parameters:

  • (String)
  • (Hash)


10
11
12
13
14
# File 'lib/depec/analyzer.rb', line 10

def initialize(dir, config)
  @dir = dir
  @name = File.basename(@dir)
  @config = Configuration.call(config).to_h
end

Instance Method Details

#analyzeHash

Returns:

  • (Hash)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/depec/analyzer.rb', line 19

def analyze
  results = {
    name: @name
  }

  @config[:targets].each do |target, options|
    klass = Object.const_get("Depec::Target::#{target.to_s.split('_').collect!{ |w| w.capitalize }.join}").new(@dir)
    results[target] = klass.used? if options[:use]
    if [:ruby, :node].include?(target)
      results[:"#{target}_version"] = klass.version if options[:version]
    end
    if target == :circle_ci
      results[:circle_ci_images] = klass.images if options[:images]
    end
    if target == :ruby
      results[:bundler_version] = klass.bundler_version if options[:bundler_version]
      options[:gem_version]&.each do |gem|
        results[:"#{gem}_gem"] = klass.gem_version(gem)
      end
    end
    if target == :node
      options[:npm_version]&.each do |npm|
        results[:"#{npm}_npm"] = klass.npm_version(npm)
      end
    end
  end

  results
end