Skip to content

Action::Result

Every call invocation on an Action will return an Action::Result instance, which provides a consistent interface:

MethodDescription
ok?true if the call succeeded, false if not.
errorUser-facing error message (string), if not ok? (else nil)
successUser-facing success message (string), if ok? (else nil)
messageUser-facing message (string), always defined (ok? ? success : error)
exceptionIf not ok? because an exception was swallowed, will be set to the swallowed exception (note: rarely used outside development; prefer to let the library automatically handle exception handling for you)
any exposed valuesguaranteed to be set if ok? (since they have outgoing presence validations by default; any missing would have failed the action)

NOTE: success and error (and so implicitly message) can be configured per-action via the messages declaration.

Clarification of exposed values

In addition to the core interface, your Action's Result class will have methods defined to read the values of any attributes that were explicitly exposed. For example, given this action and result:

ruby
class Foo
  include Action

  exposes :bar, :baz

  def call
    expose bar: 1, baz: 2
  end
end

result = Foo.call

result will have both bar and baz reader methods (which will return 1 and 2, respectively).