Class: RR::MethodDispatches::MethodMissingDispatch

Inherits:
BaseMethodDispatch show all
Defined in:
lib/rr/method_dispatches/method_missing_dispatch.rb

Instance Attribute Summary collapse

Attributes inherited from BaseMethodDispatch

#args, #block, #double

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Space::Reader

#space

Constructor Details

#initialize(subject, method_name, args, block) ⇒ MethodMissingDispatch

Returns a new instance of MethodMissingDispatch.



11
12
13
# File 'lib/rr/method_dispatches/method_missing_dispatch.rb', line 11

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

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



10
11
12
# File 'lib/rr/method_dispatches/method_missing_dispatch.rb', line 10

def method_name
  @method_name
end

#subjectObject (readonly)

Returns the value of attribute subject.



10
11
12
# File 'lib/rr/method_dispatches/method_missing_dispatch.rb', line 10

def subject
  @subject
end

Class Method Details

.original_method_missing_alias_nameObject



5
6
7
# File 'lib/rr/method_dispatches/method_missing_dispatch.rb', line 5

def original_method_missing_alias_name
  "__rr__original_method_missing"
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rr/method_dispatches/method_missing_dispatch.rb', line 15

def call
  if space.double_injection_exists?(subject, method_name)
    space.record_call(subject, method_name, args, block)
    @double = find_double_to_attempt

    if double
      double.method_call(args)
      call_yields
      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

#call_original_methodObject



37
38
39
40
41
# File 'lib/rr/method_dispatches/method_missing_dispatch.rb', line 37

def call_original_method
  double_injection.bypass_bound_method do
    call_original_method_missing
  end
end