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

Overview

Final ressults of the full run.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_tree) ⇒ Results

Returns a new instance of Results.



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

def initialize(target_tree)
  @target_tree = target_tree
end

Instance Attribute Details

#draftObject

Returns the value of attribute draft.



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

def draft
  @draft
end

#target_treeObject

Returns the value of attribute target_tree.



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

def target_tree
  @target_tree
end

Instance Method Details

#[](key) ⇒ Object



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

def[](key)
  responses[key] ||= []
end

#add_response(key, input_unit_response) ⇒ Object

Note:

this captures the latest draft



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

def add_response(key, input_unit_response)
  self[key] << input_unit_response
  input_unit_response.tap do |iur|
    next if final_response

    self.draft = iur.draft
  end
end

#appliedObject



144
145
146
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 144

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

#applied?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 156

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

#applied_commands(with_id_change: false) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 51

def applied_commands(with_id_change: false)
  results.select(&:applied?).then do |applied|
    next applied unless with_id_change

    applied.select do |result|
      # next false unless (command = result.command_result_data)
      next false unless (command = result.command_input_data)

      command.keys.include?(:newId)
    end
  end
end

#command_results(response = final_response) ⇒ Object



108
109
110
111
112
113
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 108

def command_results(response = final_response)
  response = final_response(response)
  return [] unless response

  response.results || []
end

#countObject



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

def count
  responses.values.flatten.count
end

#draft_idObject



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

def draft_id
  draft&.id
end

#errorObject

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



124
125
126
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 124

def error
  response&.error
end

#error?Boolean

Note:

it only accounts for the errors of the final publishing of the draft.

Returns:

  • (Boolean)


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

def error?
  return false unless final_response

  final_response.error?
end

#erroredObject



140
141
142
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 140

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

#errored?Boolean

Returns:

  • (Boolean)


152
153
154
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 152

def errored?
  errored.any?
end

#final_response(response = nil) ⇒ Object

Note:

it receives the final results response (when the draft gets published)



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

def final_response(response = nil)
  return @response if response.nil?

  @response = response
end

#final_response?Boolean

Returns:

  • (Boolean)


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

def final_response?
  !final_response.nil?
end

#first_erroredObject



160
161
162
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 160

def first_errored
  errored.first
end

#first_errored_idxObject



164
165
166
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 164

def first_errored_idx
  result_idx(first_errored)
end

#input_commandsObject



98
99
100
101
102
103
104
105
106
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 98

def input_commands
  keys.each_with_object([]) do |key, commands|
    self[key].each do |input|
      next unless input.is_a?(InputUnitResponse)

      commands.concat(input.commands)
    end
  end
end

#keysObject



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

def keys
  responses.keys
end

#last_appliedObject



172
173
174
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 172

def last_applied
  applied.last
end

#last_applied_idxObject



176
177
178
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 176

def last_applied_idx
  result_idx(last_applied)
end

#parent_structureObject



15
16
17
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 15

def parent_structure
  draft&.parent_structure || target_tree
end

#pendingObject



148
149
150
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 148

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

#responsesObject



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

def responses
  @responses ||= {}
end

#result_idx(result) ⇒ Object

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



136
137
138
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 136

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

#resultsObject



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

def results
  return [] unless final_response

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

#some_applied?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 168

def some_applied?
  applied.any?
end

#some_pending?Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 180

def some_pending?
  !pending.empty?
end

#statsObject



115
116
117
118
119
120
121
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 115

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

#structureObject

Note:

the result of the draft



25
26
27
# File 'lib/eco/api/usecases/graphql/helpers/location/command/results.rb', line 25

def structure
  draft&.structure
end

#structure_idObject

Note:

target parent structure id



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

def structure_id
  parent_structure&.id
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  !error?
end