Module: PayDirt::UseCase

Included in:
Base
Defined in:
lib/pay_dirt/use_case.rb

Overview

Provides the basic functionality every PayDirt service object should have.

Since:

  • 0.0.2

Instance Method Summary collapse

Instance Method Details

#load_options(*required_options, options) ⇒ Object

Load instance variables from the provided hash of dependencies.

Raises if any required dependencies (required_options) are missing from options hash. Optionally, takes and yields a block after loading options. Use this to validate dependencies.

Parameters:

  • option_names (List<String,Symbol>)

    list of keys representing required dependencies

  • options (Hash)

    A hash of dependencies

Since:

  • 0.0.2



17
18
19
20
21
22
23
24
25
# File 'lib/pay_dirt/use_case.rb', line 17

def load_options(*required_options, options)
  # Load required options
  required_options.each { |o| options = load_option(o, options) }

  # Load remaining options
  options.each_key  { |k| options = load_option(k, options) }

  block_given? ? yield : options
end

#result(success, data = nil) ⇒ Object

Returns a result object conveying success or failure (success) and any data. See PayDirt::Result.

Parameters:

  • success (Boolean)

    should the result be #successful??

  • data (Object) (defaults to: nil)

    (nil) optional, an object containing information

Since:

  • 0.0.2



37
38
39
# File 'lib/pay_dirt/use_case.rb', line 37

def result(success, data = nil)
  PayDirt::Result.new(success: success, data: data)
end