Class: DependencyWorker

Inherits:
GenericWorker show all
Includes:
VersionRequirementComparator
Defined in:
lib/cutting_edge/workers/dependency.rb

Constant Summary collapse

STATUS_TYPES =

Order is significant for purposes of calculating results

[:outdated_major, :outdated_minor, :outdated_patch, :ok, :no_requirement, :unknown]
OUTDATED_TYPES =

Which types indicate an outdated dependency. Used to calculate the total number of out-of-date dependencies.

EMPTY_STATUS_HASH =
STATUS_TYPES.inject({}){|result, type| result[type] = []; result}

Constants included from VersionRequirementComparator

VersionRequirementComparator::HIGHER_THAN

Instance Method Summary collapse

Methods included from VersionRequirementComparator

#version_difference_type, #version_requirement_diff

Methods included from WorkerHelpers

#add_to_store, #badge_worker, #delete_from_store, #get_from_store, #log_info, #mail_worker

Instance Method Details

#perform(identifier, lang, locations, dependency_types, to_addr, auth_token = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/cutting_edge/workers/dependency.rb', line 16

def perform(identifier, lang, locations, dependency_types, to_addr, auth_token = nil)
  log_info 'Running Worker!'
  @lang = get_lang(lang)
  @provider = get_provider(identifier)
  @auth_token = auth_token
  old_dependencies = get_from_store(identifier) || {}
  begin
    dependencies = {:locations => {}}
    locations.each do |name, url|
      contents = http_get(url)
      dependencies[:locations][name] = get_results(@lang.parse_file(name, contents), dependency_types)
    end
    dependencies.merge!(generate_stats(dependencies[:locations]))
    @nothing_changed = dependencies == old_dependencies
    unless @nothing_changed
      add_to_store(identifier, dependencies)
      add_to_store("diff-#{identifier}", diff_dependencies(old_dependencies[:locations], dependencies[:locations]))
    end
  ensure
    unless @nothing_changed
      badge_worker(identifier)
      mail_worker(identifier, to_addr) if to_addr && (!old_dependencies.empty? || ::CuttingEdge::ALWAYS_MAIL)
    end
    GC.start
  end
end