Class: Eco::API::UseCases::GraphQL::Helpers::Location::Command::Result
- Defined in:
- lib/eco/api/usecases/graphql/helpers/location/command/result.rb
Instance Attribute Summary collapse
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #applied? ⇒ Boolean
- #as_json ⇒ Object
- #command_id ⇒ Object
- #command_input_data ⇒ Object
- #command_result_data ⇒ Object
-
#command_type ⇒ Symbol
The command type.
- #error ⇒ Object
- #error? ⇒ Boolean
- #error_msg ⇒ Object
-
#initialize(input, result) ⇒ Result
constructor
A new instance of Result.
- #node_id ⇒ Object
- #pending? ⇒ Boolean
- #success? ⇒ Boolean
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
#input ⇒ Object (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 |
#result ⇒ Object (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
23 24 25 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 23 def applied? !pending? && success? end |
#as_json ⇒ Object
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_id ⇒ Object
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_data ⇒ Object
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_data ⇒ Object
53 54 55 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 53 def command_result_data result&.command end |
#command_type ⇒ Symbol
Returns 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 |
#error ⇒ Object
31 32 33 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 31 def error result&.error end |
#error? ⇒ Boolean
35 36 37 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 35 def error? !!error end |
#error_msg ⇒ Object
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_id ⇒ Object
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
19 20 21 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 19 def pending? !result || !success? end |
#success? ⇒ Boolean
27 28 29 |
# File 'lib/eco/api/usecases/graphql/helpers/location/command/result.rb', line 27 def success? result&.ok end |