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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, result) ⇒ Result

Returns a new instance of Result.



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

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

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



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

def input
  @input
end

#resultObject (readonly)

Returns the value of attribute result.



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

def result
  @result
end

Instance Method Details

#applied?Boolean

Returns:

  • (Boolean)


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

def applied?
  !pending?
end

#as_jsonObject



62
63
64
65
66
67
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 62

def as_json
  {
    "request"  => input,
    "response" => result.doc
  }
end

#commandObject



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

def command
  input.keys.first
end

#command_idObject



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

def command_id
  return nil unless result
  command_result["id"]
end

#command_input_dataObject



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

def command_input_data
  input[command]
end

#command_resultObject



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

def command_result
  result&.command
end

#errorObject



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

def error
  result&.error
end

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !!error
end

#error_msgObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 42

def error_msg
  return nil unless error?
  msg  = ''
  msg << "(#{command} '#{node_id}') #{error.message}\n" || ''
  return msg if error.validationErrors.empty?
  msg << "  • " + error.validationErrors.map do |err|
    err.message
  end.join("\n  • ")
  msg
end

#node_idObject



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

def node_id
  command_input_data[:nodeId]
end

#pending?Boolean

Returns:

  • (Boolean)


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

def pending?
  !result || !success?
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  result&.ok
end