Class: StudFinder::JsFanIn

Inherits:
Object
  • Object
show all
Defined in:
lib/stud_finder/js_fan_in.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

TOOL_MISSING =
'js_tools_missing'
TIMEOUT =
'js_depcruise_timeout'

Instance Method Summary collapse

Constructor Details

#initialize(repo_path:, files:, js_timeout: 60, stderr: $stderr) ⇒ JsFanIn

Returns a new instance of JsFanIn.



15
16
17
18
19
20
# File 'lib/stud_finder/js_fan_in.rb', line 15

def initialize(repo_path:, files:, js_timeout: 60, stderr: $stderr)
  @repo_path = File.expand_path(repo_path)
  @files = files
  @js_timeout = js_timeout
  @stderr = stderr
end

Instance Method Details

#callObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/stud_finder/js_fan_in.rb', line 22

def call
  return missing_tools unless node_available?

  depcruise = depcruise_binary
  return missing_tools unless depcruise

  stdout, _stderr, status = run_depcruise(depcruise)
  return missing_tools unless status.success?

  counts, fan_out_counts, edges = parse(stdout)
  Result.new(counts: counts, fan_out_counts: fan_out_counts, edges: edges, warnings: [])
rescue Timeout::Error
  warn(TIMEOUT)
  Result.new(counts: zero_counts, fan_out_counts: zero_counts, edges: empty_edges, warnings: [TIMEOUT])
rescue JSON::ParserError, KeyError, TypeError
  missing_tools
end