Class: GhInspector::Sidekick

Inherits:
Object
  • Object
show all
Defined in:
lib/gh_inspector/sidekick.rb

Overview

The Sidekick is the one who does all the real work. They take the query, get the GitHub API results, etc then pass them back to the inspector who gets the public API credit.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inspector, repo_owner, repo_name) ⇒ Sidekick

Returns a new instance of Sidekick.



12
13
14
15
16
17
# File 'lib/gh_inspector/sidekick.rb', line 12

def initialize(inspector, repo_owner, repo_name)
  self.inspector = inspector
  self.repo_owner = repo_owner
  self.repo_name = repo_name
  self.using_deprecated_method = false
end

Instance Attribute Details

#inspectorObject

Returns the value of attribute inspector.



10
11
12
# File 'lib/gh_inspector/sidekick.rb', line 10

def inspector
  @inspector
end

#repo_nameObject

Returns the value of attribute repo_name.



10
11
12
# File 'lib/gh_inspector/sidekick.rb', line 10

def repo_name
  @repo_name
end

#repo_ownerObject

Returns the value of attribute repo_owner.



10
11
12
# File 'lib/gh_inspector/sidekick.rb', line 10

def repo_owner
  @repo_owner
end

#using_deprecated_methodObject

Returns the value of attribute using_deprecated_method.



10
11
12
# File 'lib/gh_inspector/sidekick.rb', line 10

def using_deprecated_method
  @using_deprecated_method
end

Instance Method Details

#search(query, delegate) ⇒ Object

Searches for a query, with a UI delegate



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
48
49
50
51
52
# File 'lib/gh_inspector/sidekick.rb', line 20

def search(query, delegate)
  validate_delegate(delegate)

  delegate.inspector_started_query(query, inspector)
  url = url_for_request query

  begin
    results = get_api_results(url)
  rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
    delegate.inspector_could_not_create_report(e, query, inspector)
    return
  end

  report = parse_results query, results

  # TODO: progress callback

  if report.issues.any?
    if self.using_deprecated_method
      delegate.inspector_successfully_recieved_report(report, inspector)
    else
      delegate.inspector_successfully_received_report(report, inspector)
    end
  else
    if self.using_deprecated_method
      delegate.inspector_recieved_empty_report(report, inspector)
    else
      delegate.inspector_received_empty_report(report, inspector)
    end
  end

  report
end

#verboseObject



54
55
56
# File 'lib/gh_inspector/sidekick.rb', line 54

def verbose
  self.inspector.verbose
end