Class: Ballast::Context

Inherits:
Interactor::Context
  • Object
show all
Defined in:
lib/ballast/context.rb

Overview

A context for an operation. It is basically a Hash with few enhancements, like owner, errors and output support.

Class Method Summary (collapse)

Instance Method Summary (collapse)

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block)

Lookups missing methods in the delegatee hash.

Parameters:

  • method (Symbol)

    The method to lookup.

  • args (Array)

    The arguments passed to the method. This is ignored.

  • block (Proc)

    The block passed to the method. This is ignored.

Returns:

  • (Object)

    The value for the method, if present.



28
29
30
31
32
33
34
35
36
# File 'lib/ballast/context.rb', line 28

def method_missing(method, *args, &block)
  object = __getobj__

  if object[method] then
    object[method]
  else
    super(method, *args, &block)
  end
end

Class Method Details

+ (Object) build(owner, additional = {})

Builds a new context.

Parameters:

  • owner (Object)

    The owner of this context.

  • additional (Hash) (defaults to: {})

    Additional parameters to include into the context.



13
14
15
16
17
18
19
20
# File 'lib/ballast/context.rb', line 13

def self.build(owner, additional = {})
  super({
    owner: owner,
    errors: [],
    output: nil,
    response: HashWithIndifferentAccess.new
  }.merge(additional).ensure_access(:indifferent))
end