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



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

def applied
  @applied ||= results.select(&:applied?)
end

#applied?Boolean

Returns:

  • (Boolean)


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

def applied?
  results.all?(&:applied?)
end

#countObject



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

def count
  results.count
end

#errorObject

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



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

def error
  response&.error
end

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !!error
end

#erroredObject



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

def errored
  @errored ||= results.select(&:error?)
end

#errored?Boolean

Returns:

  • (Boolean)


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

def errored?
  errored.any?
end

#first_erroredObject



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

def first_errored
  errored.first
end

#first_errored_idxObject



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

def first_errored_idx
  idx(first_errored)
end

#force?Boolean

Was this configured to force-continue on command error?

Returns:

  • (Boolean)


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

def force?
  input[:force]
end

#idx(result) ⇒ Object



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

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

#input_idx(input) ⇒ Object



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

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

#input_result(input) ⇒ Object



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

def input_result(input)
  results_by_input[input]
end

#last_appliedObject



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

def last_applied
  applied.last
end

#last_applied_idxObject



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

def last_applied_idx
  idx(last_applied)
end

#pendingObject



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

def pending
  @pending ||= results.select(&:pending?)
end

#resultsObject



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

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)


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

def some_applied?
  applied.count.positive?
end

#some_pending?Boolean

Returns:

  • (Boolean)


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

def some_pending?
  !pending.empty?
end

#statsObject



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

def stats
  msg       = ''
  msg << "  • Errored: #{errored.count} #{first_err_str}\n" if errored?
  msg << "  • Applied: #{errored.count} #{last_okay_str}\n" if some_applied?
  msg << "  • Pending: #{pending.count}\n"                  if some_pending?
  msg
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  !error? && results.all?(&:success?)
end