Class: StubRequests::DSL::MethodDefinition

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

Overview

Class DefineMethod generates method definition for a stubbed endpoint

Author:

Since:

  • 0.1.4

Constant Summary collapse

BLOCK_ARG =

Returns:

Since:

  • 0.1.4

"&block"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint_id, route_params) ⇒ MethodDefinition

Initialize a new endpoint of StubRequests::DSL::MethodDefinition

Parameters:

  • endpoint_id (Symbol)

    the id of a registered endpoint

  • route_params (Array<Symbol>)

    the route parameter keys

Since:

  • 0.1.4



31
32
33
34
# File 'lib/stub_requests/dsl/method_definition.rb', line 31

def initialize(endpoint_id, route_params)
  @endpoint_id  = endpoint_id
  @route_params = route_params
end

Instance Attribute Details

#endpoint_idObject (readonly)

Since:

  • 0.1.4



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

def endpoint_id
  @endpoint_id
end

#route_paramsObject (readonly)

Since:

  • 0.1.4



23
24
25
# File 'lib/stub_requests/dsl/method_definition.rb', line 23

def route_params
  @route_params
end

Instance Method Details

#nameString

The name of this method

Returns:

  • (String)

    a string prefixed with stub_, "stub_documents_show"

Since:

  • 0.1.4



42
43
44
# File 'lib/stub_requests/dsl/method_definition.rb', line 42

def name
  @name ||= "stub_#{endpoint_id}"
end

#to_sObject Also known as: to_str

Since:

  • 0.1.4



46
47
48
49
50
51
52
# File 'lib/stub_requests/dsl/method_definition.rb', line 46

def to_s
  <<~METHOD
    def #{name}(#{keywords})
      StubRequests.stub_endpoint(:#{endpoint_id}, #{arguments})
    end
  METHOD
end