class Hesburgh::Lib::MockRunner
A class to assist in circumventing the seething underlayer of potential runners and cut quick to the working with the callbacks.
@example
context = [] runner = MockRunner.new(context: context, run_with: :input, yields: :yielded_value, callback_name: :success) runner.run(:input) do |on| on.success {|output| context << output } end context == [:yielded_value] => true
@see Hesrbugh::Lib::Runner @see Hesrbugh::Lib::NamedCallbacks
Public Class Methods
new(options = {})
click to toggle source
# File lib/hesburgh/lib/mock_runner.rb, line 27 def initialize(options = {}) @yields = options.fetch(:yields) @callback_name = options.fetch(:callback_name) @run_with = __wrap__(options.fetch(:run_with)) # Because the context may automatically be getting assigned by the # controller. @run_with.unshift(options[:context]) if options.key?(:context) end
Public Instance Methods
method_missing(method_name) { |yields| ... }
click to toggle source
# File lib/hesburgh/lib/mock_runner.rb, line 43 def method_missing(method_name, &_block) return @callback_name, *yield(@yields) if @callback_name.to_s == method_name.to_s end
run(*args) { |self| ... }
click to toggle source
# File lib/hesburgh/lib/mock_runner.rb, line 37 def run(*args) raise RunWithMismatchError, actual: args, expected: @run_with unless @run_with == args return yield(self) if block_given? return @callback_name, *@yields end
Private Instance Methods
__wrap__(object)
click to toggle source
# File lib/hesburgh/lib/mock_runner.rb, line 49 def __wrap__(object) if object.nil? [] elsif object.respond_to?(:to_ary) object.to_ary || [object] else [object] end end