Class: RSpec::SleepingKingStudios::Deferred::Call

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/sleeping_king_studios/deferred/call.rb

Overview

Value object representing a deferred call to a method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name, *arguments, **keywords, &block) ⇒ Call

Returns a new instance of Call.

Parameters:

  • method_name (String, Symbol)

    the name of the method to call.

  • arguments (Array)

    the arguments to pass to the method.

  • keywords (Hash)

    the keywords to pass to the method.

  • block (Proc)

    the block to pass to the method.



14
15
16
17
18
19
20
21
# File 'lib/rspec/sleeping_king_studios/deferred/call.rb', line 14

def initialize(method_name, *arguments, **keywords, &block)
  @method_name = method_name
  @arguments   = arguments
  @keywords    = keywords
  @block       = block

  validate_parameters!
end

Instance Attribute Details

#argumentsArray (readonly)

Returns the arguments to pass to the method.

Returns:

  • (Array)

    the arguments to pass to the method.



24
25
26
# File 'lib/rspec/sleeping_king_studios/deferred/call.rb', line 24

def arguments
  @arguments
end

#blockProc (readonly)

Returns the block to pass to the method.

Returns:

  • (Proc)

    the block to pass to the method.



27
28
29
# File 'lib/rspec/sleeping_king_studios/deferred/call.rb', line 27

def block
  @block
end

#keywordsHash (readonly)

Returns the keywords to pass to the method.

Returns:

  • (Hash)

    the keywords to pass to the method.



30
31
32
# File 'lib/rspec/sleeping_king_studios/deferred/call.rb', line 30

def keywords
  @keywords
end

#method_nameString, Symbol (readonly)

Returns the name of the method to call.

Returns:

  • (String, Symbol)

    the name of the method to call.



33
34
35
# File 'lib/rspec/sleeping_king_studios/deferred/call.rb', line 33

def method_name
  @method_name
end

Instance Method Details

#==(other) ⇒ Boolean

Compares the other object with the deferred call.

Returns true if and only if:

  • The other object is an instance of Deferred::Call.
  • The other object's method name and type match the deferred call.
  • The other object's arguments, keywords, and block all match the deferred call.

Parameters:

  • other (Object)

    the object to compare.

Returns:

  • (Boolean)

    true if the other matches the deferred call; otherwise false.



47
48
49
50
51
52
53
# File 'lib/rspec/sleeping_king_studios/deferred/call.rb', line 47

def ==(other)
  other.class == self.class &&
    other.method_name == method_name &&
    other.arguments == arguments &&
    other.keywords == keywords &&
    other.block == block
end

#call(receiver) ⇒ Object

Invokes the deferred method call on the receiver.

Parameters:

  • receiver (Object)

    the receiver for the method call.

Returns:

  • (Object)

    the returned value of the method call.



60
61
62
# File 'lib/rspec/sleeping_king_studios/deferred/call.rb', line 60

def call(receiver)
  receiver.send(method_name, *arguments, **keywords, &block)
end