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)


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

def applied?
  !pending? && success?
end

#as_jsonObject



67
68
69
70
71
72
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 67

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

#command_idObject



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

def command_id
  return unless command_result_data

  command_result_data['id']
end

#command_input_dataObject



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

def command_input_data
  input[command]
end

#command_result_dataObject



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

def command_result_data
  result&.command
end

#command_typeSymbol

Returns the command type.

Returns:

  • (Symbol)

    the command type



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

def command_type
  input.keys.first
end

#errorObject



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

def error
  result&.error
end

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  !!error
end

#error_msgObject



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

def error_msg
  return nil unless error?

  msg  = []
  msg << "(#{command} '#{node_id}') #{error.message}"

  feed = []
  feed.concat(error.validationErrors.map(&:message)) unless error.validationErrors.empty?
  feed << "Command: #{JSON.pretty_generate(command_input_data)}"

  msg  << "  * #{feed.join("\n  * ")}"
  msg.join("\n")
end

#node_idObject



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

def node_id
  command_input_data[:nodeId]
end

#pending?Boolean

Returns:

  • (Boolean)


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

def pending?
  !result || !success?
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  result&.ok
end