Sha256: c9ed8a7f303a389c163075b843589ccd6fe8baa8951b36a56960c708795d1335

Contents?: true

Size: 1.25 KB

Versions: 19

Compression:

Stored size: 1.25 KB

Contents

module Eco::API::UseCases::GraphQL::Helpers::Location::Command
  class Result
    attr_reader :input, :result

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

    def command
      input.keys.first
    end

    def command_input_data
      input[command]
    end

    def node_id
      command_input_data[:nodeId]
    end

    def pending?
      !result || !success?
    end

    def applied?
      !pending?
    end

    def success?
      result&.ok
    end

    def error
      result&.error
    end

    def error?
      !!error
    end

    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

    def command_result
      result&.command
    end

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

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

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
eco-helpers-3.0.4 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-3.0.3 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-3.0.2 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-3.0.1 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-3.0.0 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.25 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.24 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.23 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.22 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.21 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.20 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.19 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.18 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.17 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.16 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.15 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.14 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.13 lib/eco/api/usecases/graphql/helpers/location/command/result.rb
eco-helpers-2.7.12 lib/eco/api/usecases/graphql/helpers/location/command/result.rb