Sha256: 7fc95d2533dad7e20403bac9f676e2d6a28cb6ea9648206af7230b2e2af6be46

Contents?: true

Size: 1.16 KB

Versions: 12

Compression:

Stored size: 1.16 KB

Contents

module RestPack::Service
  class Command < Mutations::Command
    attr_accessor :response

    def run
      @response = Response.new

      begin
        init
        mutation = super

        if mutation.errors
          mutation.errors.message.each do |error|
            @response.add_error(error[0], error[1].gsub(error[0].capitalize, ''))
          end

          @response.status ||= :unprocessable_entity
        else
          @response.status ||= :ok
        end

        if @response.status == :ok
          @response.result = mutation.result if mutation.result
        end
      rescue Exception => e
        puts "---COMMAND EXCEPTION---"
        puts e.message #TODO: GJ: logging
        puts e.backtrace
        puts "-----------------------"

        @response.add_error(:base, 'Service Error')
        @response.status = :internal_service_error
      end

      @response
    end

    def init
    end

    def status(status)
      @response.status = status
    end

    def valid?
      !has_errors?
    end

    def service_error(message)
      field_error :base, message
    end

    def field_error(key, message)
      add_error key, key, message
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
restpack_service-0.0.54 lib/restpack_service/command.rb
restpack_service-0.0.53 lib/restpack_service/command.rb
restpack_service-0.0.52 lib/restpack_service/command.rb
restpack_service-0.0.51 lib/restpack_service/command.rb
restpack_service-0.0.50 lib/restpack_service/command.rb
restpack_service-0.0.49 lib/restpack_service/command.rb
restpack_service-0.0.48 lib/restpack_service/command.rb
restpack_service-0.0.47 lib/restpack_service/command.rb
restpack_service-0.0.46 lib/restpack_service/command.rb
restpack_service-0.0.45 lib/restpack_service/command.rb
restpack_service-0.0.44 lib/restpack_service/command.rb
restpack_service-0.0.43 lib/restpack_service/command.rb