Module: Crossbeam

Defined in:
lib/crossbeam.rb,
lib/crossbeam/error.rb,
lib/crossbeam/errors.rb,
lib/crossbeam/output.rb,
lib/crossbeam/result.rb,
lib/crossbeam/version.rb,
lib/crossbeam/callbacks.rb

Overview

Crossbeam module to include with your service classes

Defined Under Namespace

Modules: Callbacks, ClassMethods, Output Classes: ArguementError, Error, Errors, Failure, NotImplementedError, Result, UndefinedMethod

Constant Summary collapse

VERSION =

Returns:

  • (String)
'0.1.1'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ void

This method returns an undefined value.

Used to include/extend modules into the current class

Parameters:

  • base (Object)


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/crossbeam.rb', line 23

def self.included(base)
  base.class_eval do
    include(ActiveModel::Validations) # Used to add validation errors to a class
    extend(Dry::Initializer) # Used to allow for easy attribute initializations
    extend(ClassMethods) # Class methods used to initialize the service call
    include(Output)
    include(Callbacks) # Callbacks that get called before/after `.call` is referenced

    # Holds the service call results and current class call for Crossbeam Instance
    attr_reader :result, :klass
  end
end

Instance Method Details

#errorsHash

Used to return a list of errors for the current call

Returns:

  • (Hash)


103
104
105
106
107
# File 'lib/crossbeam.rb', line 103

def errors
  return {} unless @result

  @result.errors
end

#fail!(error) ⇒ void

This method returns an undefined value.

Force the job to raise an exception and stop the rest of the service call

Parameters:

  • error (String)

Raises:



84
85
86
# File 'lib/crossbeam.rb', line 84

def fail!(error)
  raise(Crossbeam::Failure, error)
end