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



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

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



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

def command_id
  return 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



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

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
52
53
54
# 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}"

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

  msg  << "#{feed.join("\n  • ")}"
  msg.join("\n")
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