Sha256: ecfe03fdde4abc5524a822cdba5a9f1d444f18deeb0a31ce3e68ba0b3ecf1d77

Contents?: true

Size: 1.28 KB

Versions: 18

Compression:

Stored size: 1.28 KB

Contents

#
# This file is part of the ballast gem. Copyright (C) 2013 and above Shogun <shogun@cowtech.it>.
# Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php.
#

module Ballast
  # A context for an operation. It is basically a Hash with few enhancements, like owner, errors and output support.
  class Context < Interactor::Context
    # Builds a new context.
    #
    # @param owner [Object] The owner of this context.
    # @param additional [Hash] Additional parameters to include into the context.
    def self.build(owner, additional = {})
      super({
        owner: owner,
        errors: [],
        output: nil,
        response: HashWithIndifferentAccess.new
      }.merge(additional).ensure_access(:indifferent))
    end

    # Lookups missing methods in the delegatee hash.
    #
    # @param method [Symbol] The method to lookup.
    # @param args [Array] The arguments passed to the method. *This is ignored.*
    # @param block [Proc] The block passed to the method. *This is ignored.*
    # @return [Object] The value for the method, if present.
    def method_missing(method, *args, &block)
      object = __getobj__

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
ballast-1.9.3 lib/ballast/context.rb
ballast-1.9.2 lib/ballast/context.rb
ballast-1.9.1 lib/ballast/context.rb
ballast-1.9.0 lib/ballast/context.rb
ballast-1.8.0 lib/ballast/context.rb
ballast-1.7.0 lib/ballast/context.rb
ballast-1.6.0 lib/ballast/context.rb
ballast-1.5.3 lib/ballast/context.rb
ballast-1.5.2 lib/ballast/context.rb
ballast-1.5.1 lib/ballast/context.rb
ballast-1.5.0 lib/ballast/context.rb
ballast-1.4.0 lib/ballast/context.rb
ballast-1.3.0 lib/ballast/context.rb
ballast-1.2.0 lib/ballast/context.rb
ballast-1.1.2 lib/ballast/context.rb
ballast-1.1.1 lib/ballast/context.rb
ballast-1.1.0 lib/ballast/context.rb
ballast-1.0.0 lib/ballast/context.rb