Class: StubRequests::DSL::DefineMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/stub_requests/dsl/define_method.rb

Overview

Class DefineMethod defines helper methods for stubbed endpoints

Author:

Since:

  • 0.1.4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition, receiver) ⇒ DefineMethod

Initialize a new instance of DefineMethod

Parameters:

  • definition (MethodDefinition)

    the method definition

  • receiver (Module)

    the receiver of the method definition

Since:

  • 0.1.4



28
29
30
31
# File 'lib/stub_requests/dsl/define_method.rb', line 28

def initialize(definition, receiver)
  @receiver   = receiver
  @definition = definition
end

Instance Attribute Details

#definitionObject (readonly)

Since:

  • 0.1.4



15
16
17
# File 'lib/stub_requests/dsl/define_method.rb', line 15

def definition
  @definition
end

#receiverObject (readonly)

Since:

  • 0.1.4



19
20
21
# File 'lib/stub_requests/dsl/define_method.rb', line 19

def receiver
  @receiver
end

Instance Method Details

#definevoid

This method returns an undefined value.

Define the MethodDefinition#to_s on the receiver

Since:

  • 0.1.4



39
40
41
42
43
44
45
46
# File 'lib/stub_requests/dsl/define_method.rb', line 39

def define
  Docile.dsl_eval(receiver) do
    silence_redefinition_of_method(definition.name)
    module_eval <<~METHOD, __FILE__, __LINE__ + 1
      #{definition}
    METHOD
  end
end