Exception: Hexx::ServiceInvalid

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/hexx/service_invalid.rb

Overview

The exception to be risen by invalid services.

Examples:

service GetItem < Hexx::Service
  allow_params :uuid
  validates :uuid, presence: true
  def run
    validate!
  end
end

service = GetItem.new
service.run # => fails with the {Hexx::ServiceInvalid}.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messageString (readonly)

Returns a default text message for the exception.

Examples:

error = Hexx::ServiceInvalid.new service
error.message # => "Service invalid: #<Hexx::Service... >"

Returns:

  • (String)

    The message.


48
49
50
# File 'lib/hexx/service_invalid.rb', line 48

def message
  "Service invalid: #{ service.inspect }"
end

#messagesArray<Hexx::Message> (readonly)

Returns a list of error messages from the service.

Examples:

service.errors.add :base, "some error"

error = Hexx::ServiceInvalid.new service
error.messages
# => [#<Hexx::Message @type="error" @text="some error" >]

Returns:


63
64
65
# File 'lib/hexx/service_invalid.rb', line 63

def messages
  errors.map { |text| Message.new type: "error", text: text }
end

#serviceHexx::Service (readonly)

Returns The invalid service object.

Returns:


22
23
24
# File 'lib/hexx/service_invalid.rb', line 22

def service
  @service
end

Class Method Details

.new(service) ⇒ Hexx::ServiceInvalid

Initializes the exception.

Examples:

fail Hexx::ServiceInvalid.new service

Parameters:

Returns:

Raises:

  • (ArgumentError)

    if the argument is not a service object.


# File 'lib/hexx/service_invalid.rb', line 24

Instance Method Details

#errorsObject (private)


69
70
71
# File 'lib/hexx/service_invalid.rb', line 69

def errors
  service.errors.messages.values.flatten
end