Class: Impersonator::Method

Inherits:
Struct
  • Object
show all
Defined in:
lib/impersonator/method.rb

Overview

A method instance

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject

Arguments passed to the method invocation



3
4
5
# File 'lib/impersonator/method.rb', line 3

def arguments
  @arguments
end

#blockObject

Returns the value of attribute block

Returns:

  • (Object)

    the current value of block



3
4
5
# File 'lib/impersonator/method.rb', line 3

def block
  @block
end

#matching_configurationObject

The configuration that will be used to match the method invocation at replay mode



3
4
5
# File 'lib/impersonator/method.rb', line 3

def matching_configuration
  @matching_configuration
end

#nameObject

Method name



3
4
5
# File 'lib/impersonator/method.rb', line 3

def name
  @name
end

Instance Method Details

#==(other_method) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/impersonator/method.rb', line 43

def ==(other_method)
  my_arguments = arguments.dup
  other_arguments = other_method.arguments.dup
  matching_configuration&.ignored_positions&.each do |ignored_position|
    my_arguments.delete_at(ignored_position)
    other_arguments.delete_at(ignored_position)
  end

  name == other_method.name && my_arguments == other_arguments &&
    !block_spy == !other_method.block_spy
end

#block_spyBlockSpy

The spy used to spy the block yield invocations

Returns:



23
24
25
26
27
# File 'lib/impersonator/method.rb', line 23

def block_spy
  return nil if !@block_spy && !block

  @block_spy ||= BlockSpy.new(actual_block: block)
end

#encode_with(coder) ⇒ Object



36
37
38
39
40
41
# File 'lib/impersonator/method.rb', line 36

def encode_with(coder)
  coder['name'] = name
  coder['arguments'] = arguments
  coder['block_spy'] = block_spy
  coder['matching_configuration'] = matching_configuration
end

#init_with(coder) ⇒ Object



29
30
31
32
33
34
# File 'lib/impersonator/method.rb', line 29

def init_with(coder)
  self.name = coder['name']
  self.arguments = coder['arguments']
  self.matching_configuration = coder['matching_configuration']
  @block_spy = coder['block_spy']
end

#to_sObject



10
11
12
13
14
15
16
17
18
# File 'lib/impersonator/method.rb', line 10

def to_s
  string = name.to_s

  arguments_string = arguments&.collect(&:to_s)&.join(', ')

  string << "(#{arguments_string})"
  string << ' {with block}' if block
  string
end