Module: Diffend::Voting

Defined in:
lib/diffend/voting.rb,
lib/diffend/voting/request.rb,
lib/diffend/voting/versions/local.rb,
lib/diffend/voting/versions/remote.rb

Overview

Verifies voting verdicts for gems

Defined Under Namespace

Modules: Request, Versions

Class Method Summary collapse

Class Method Details

.build_allow_message(command, response) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/diffend/voting.rb', line 56

def build_allow_message(command, response)
  <<~MSG
    \nDiffend reported an allow verdict for #{command} command for this project.\n
    All of our #{response['allows_count'] + response['denies_count']} checks succeeded.\n
    #{response['review_url']}\n
  MSG
end

.build_deny_message(command, response) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/diffend/voting.rb', line 64

def build_deny_message(command, response)
  <<~MSG
    \nDiffend reported a deny verdict for #{command} command for this project.\n
    #{response['denies_count']} out of our #{response['allows_count'] + response['denies_count']} checks failed. Please go to the url below and review the issues.\n
    #{response['review_url']}\n
  MSG
end

.build_error(response) ⇒ Object



27
28
29
30
31
32
# File 'lib/diffend/voting.rb', line 27

def build_error(response)
  build_error_message(response)
    .tap(&Bundler.ui.method(:error))

  exit 1
end

.build_error_message(response) ⇒ Object



49
50
51
52
53
54
# File 'lib/diffend/voting.rb', line 49

def build_error_message(response)
  <<~MSG
    \nDiffend returned an error for your request.\n
    #{response['error']}\n
  MSG
end

.build_message(command, response) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/diffend/voting.rb', line 17

def build_message(command, response)
  if response.key?('error')
    build_error(response)
  elsif response.key?('action')
    build_verdict(command, response)
  else
    raise UnsupportedResponse, response['action']
  end
end

.build_verdict(command, response) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/diffend/voting.rb', line 34

def build_verdict(command, response)
  case response['action']
  when 'allow'
    build_allow_message(command, response)
      .tap(&Bundler.ui.method(:confirm))
  when 'deny'
    build_deny_message(command, response)
      .tap(&Bundler.ui.method(:error))

    exit 1
  else
    raise UnsupportedAction, response['action']
  end
end

.call(command, definition) ⇒ Object

Build verdict

Parameters:

  • command (String)

    either install or update

  • definition (Bundler::Definition)

    definition for your source



11
12
13
14
15
# File 'lib/diffend/voting.rb', line 11

def call(command, definition)
  Versions::Remote
    .call(command, definition)
    .tap { |response| build_message(command, response) }
end