Class: Eco::API::UseCases::GraphQL::Helpers::Location::Command::Results

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/usecases/graphql/helpers/location/command/results.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, response) ⇒ Results

Returns a new instance of Results.



5
6
7
8
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 5

def initialize(input, response)
  @input    = input
  @response = response
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



3
4
5
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 3

def input
  @input
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 3

def response
  @response
end

Instance Method Details

#appliedObject



82
83
84
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 82

def applied
  @applied ||= results.select {|r| r.applied?}
end

#applied?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 86

def applied?
  results.all? {|r| r.applied?}
end

#countObject



50
51
52
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 50

def count
  results.count
end

#errorObject

Overal errors (i.e. ID clashes between different structures)



32
33
34
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 32

def error
  response&.error
end

#error?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 36

def error?
  !!error
end

#erroredObject



66
67
68
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 66

def errored
  @errored ||= results.select {|r| r.error?}
end

#errored?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 70

def errored?
  !errored.empty?
end

#first_erroredObject



74
75
76
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 74

def first_errored
  errored.first
end

#first_errored_idxObject



78
79
80
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 78

def first_errored_idx
  idx(first_errored)
end

#force?Boolean

Was this configured to force-continue on command error?

Returns:

  • (Boolean)


21
22
23
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 21

def force?
  input[:force]
end

#idx(result) ⇒ Object



62
63
64
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 62

def idx(result)
  results.index(result)
end

#input_idx(input) ⇒ Object



58
59
60
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 58

def input_idx(input)
  results.index(input_result(input))
end

#input_result(input) ⇒ Object



54
55
56
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 54

def input_result(input)
  results_by_input[input]
end

#last_appliedObject



94
95
96
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 94

def last_applied
  applied.last
end

#last_applied_idxObject



98
99
100
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 98

def last_applied_idx
  idx(last_applied)
end

#pendingObject



102
103
104
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 102

def pending
  @pending ||= results.select {|r| r.pending?}
end

#resultsObject



44
45
46
47
48
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 44

def results
  @results ||= input_commands.zip(response_results).each_with_object([]) do |(i, r), results|
    results << Result.new(i, r)
  end
end

#some_applied?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 90

def some_applied?
  applied.count > 0
end

#some_pending?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 106

def some_pending?
  !pending.empty?
end

#statsObject



10
11
12
13
14
15
16
17
18
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 10

def stats
  msg  = ''
  first_err = force? ? '' : "(stopped on node: '#{first_errored&.node_id}' - idx: #{first_errored_idx})"
  msg << "  • Errored: #{errored.count} #{first_err}\n" if errored?
  last_okay = force? ? '' : "(last node done: '#{last_applied&.node_id}' - idx: #{last_applied_idx})"
  msg << "  • Applied: #{errored.count} #{last_okay}\n" if some_applied?
  msg << "  • Pending: #{pending.count}\n"              if some_pending?
  msg
end

#success?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 40

def success?
  !error? && results.all? {|r| r.success?}
end