class Object

Public Instance Methods

build_middleware(name) click to toggle source

rubocop:disable Metrics/AbcSize

# File lib/coach/rspec.rb, line 9
def build_middleware(name)
  Class.new(Coach::Middleware) do
    # To access `name`, we need to use `define_method` instead of `def`
    define_method(:to_s) { "<Middleware#{name}>" }
    define_method(:name) { name }
    define_singleton_method(:name) { name }

    def call
      config[:callback].call if config.include?(:callback)
      log_metadata(**{ name.to_sym => true })

      response = [name + config.except(:callback).inspect.to_s]

      # Build up a list of middleware called, in the order they were called
      if next_middleware
        response.concat(next_middleware.call)
      else
        response
      end
    end
  end
end
call() click to toggle source
# File lib/coach/rspec.rb, line 16
def call
  config[:callback].call if config.include?(:callback)
  log_metadata(**{ name.to_sym => true })

  response = [name + config.except(:callback).inspect.to_s]

  # Build up a list of middleware called, in the order they were called
  if next_middleware
    response.concat(next_middleware.call)
  else
    response
  end
end
null_middleware() click to toggle source

rubocop:enable Metrics/AbcSize

# File lib/coach/rspec.rb, line 33
def null_middleware
  double(call: nil)
end