Class: Cuprum::Rails::Result

Inherits:
Cuprum::Result
  • Object
show all
Defined in:
lib/cuprum/rails/result.rb

Overview

Result class representing the result of calling an action.

In addition to the standard properties inherited from Cuprum::Result, each Cuprum::Rails::Result also includes a #metadata property. This represents secondary information about the result that may be relevant for rendering or displaying the data, but is not part of the requested value. For example. information about the current controller would be metadata, as would the current authentication session.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error: nil, metadata: {}, status: nil, value: nil) ⇒ Result

Returns a new instance of Result.

Parameters:

  • value (Object) (defaults to: nil)

    the value returned by calling the action.

  • error (Cuprum::Error) (defaults to: nil)

    the error (if any) generated when the action was called.

  • metadata (Hash{Symbol => Object}) (defaults to: {})

    the request or action metadata.

  • status (String, Symbol, nil) (defaults to: nil)

    the status of the result. Must be :success, :failure, or nil.



21
22
23
24
25
# File 'lib/cuprum/rails/result.rb', line 21

def initialize(error: nil, metadata: {}, status: nil, value: nil)
  super(error: error, status: status, value: value)

  @metadata = 
end

Instance Attribute Details

#metadataHash{Symbol => Object} (readonly)

Returns the request or action metadata.

Returns:

  • (Hash{Symbol => Object})

    the request or action metadata.



28
29
30
# File 'lib/cuprum/rails/result.rb', line 28

def 
  @metadata
end

Instance Method Details

#propertiesHash{Symbol => Object} Also known as: to_h

Returns a Hash representation of the result.

Returns:

  • (Hash{Symbol => Object})

    a Hash representation of the result.



31
32
33
# File 'lib/cuprum/rails/result.rb', line 31

def properties
  super().merge(metadata: )
end