Sha256: 16361c0f1ae6648ec930190800d6975f0ab8098e641f0d0080d5fc43a45d0742

Contents?: true

Size: 1.91 KB

Versions: 20

Compression:

Stored size: 1.91 KB

Contents

module RR
  module MethodDispatches
    class MethodMissingDispatch < BaseMethodDispatch
      extend(Module.new do
        def original_method_missing_alias_name
          "__rr__original_method_missing"
        end
      end)

      attr_reader :subject, :subject_class, :method_name
      def initialize(subject, subject_class, method_name, args, block)
        @subject, @subject_class, @method_name, @args, @block = subject, subject_class, method_name, args, block
      end

      def call
        if Injections::DoubleInjection.exists?(subject_class, method_name)
          @double = find_double_to_attempt
          if double
            return_value = extract_subject_from_return_value(call_implementation)
            if after_call_proc
              extract_subject_from_return_value(after_call_proc.call(return_value))
            else
              return_value
            end
          else
            double_not_found_error
          end
        else
          call_original_method
        end
      end

      def call_original_method
        Injections::DoubleInjection.find_or_create(subject_class, method_name).dispatch_method_delegates_to_dispatch_original_method do
          call_original_method_missing
        end
      end

      protected
      def call_implementation
        if implementation_is_original_method?
          space.record_call(subject, method_name, args, block)
          double.method_call(args)
          call_original_method
        else
          if double_injection = Injections::DoubleInjection.find(subject_class, method_name)
            double_injection.bind_method
            # The DoubleInjection takes care of calling double.method_call
            subject.__send__(method_name, *args, &block)
          else
            nil
          end
        end
      end

      def double_injection
        Injections::DoubleInjection.find_or_create(subject_class, method_name)
      end
    end
  end
end

Version data entries

20 entries across 16 versions & 5 rubygems

Version Path
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/method_dispatches/method_missing_dispatch.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/method_dispatches/method_missing_dispatch.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.3/vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/method_dispatches/method_missing_dispatch.rb
bitclust-core-0.5.3 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/method_dispatches/method_missing_dispatch.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/bitclust-core-0.5.1/vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/method_dispatches/method_missing_dispatch.rb
bitclust-core-0.5.2 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/method_dispatches/method_missing_dispatch.rb
bitclust-core-0.5.1 vendor/bundle/ruby/1.9.1/gems/rr-1.0.4/lib/rr/method_dispatches/method_missing_dispatch.rb
mcmire-rr-1.0.5.rc1 lib/rr/method_dispatches/method_missing_dispatch.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
rr-1.0.4 lib/rr/method_dispatches/method_missing_dispatch.rb
rr-1.0.3 lib/rr/method_dispatches/method_missing_dispatch.rb
vim-jar-0.1.2.0001 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
vim-jar-0.1.2 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
vim-jar-0.1.1 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
vim-jar-0.1.0 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
vim-jar-0.0.3 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
vim-jar-0.0.2 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
vim-jar-0.0.1 bundler/ruby/1.8/gems/rr-1.0.2/lib/rr/method_dispatches/method_missing_dispatch.rb
rr-1.0.2 lib/rr/method_dispatches/method_missing_dispatch.rb