class StubRequests::DSL::MethodDefinition

Class DefineMethod generates method definition for a stubbed endpoint

@author Mikael Henriksson <mikael@zoolutions.se> @since 0.1.4

Constants

BLOCK_ARG

@return [String]

Attributes

endpoint_id[R]

@!attribute [r] endpoint_id

@return [Symbol] the id of a registered endpoint
route_params[R]

@!attribute [r] route_params

@return [Array<Symbol>] the URI parameters for the endpoint

Public Class Methods

new(endpoint_id, route_params) click to toggle source

Initialize a new endpoint of {MethodDefinition}

@param [Symbol] endpoint_id the id of a registered endpoint @param [Array<Symbol>] route_params the route parameter keys

# 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

Public Instance Methods

name() click to toggle source

The name of this method

@return [String] a string prefixed with stub_, `“stub_documents_show”`

# File lib/stub_requests/dsl/method_definition.rb, line 42
def name
  @name ||= "stub_#{endpoint_id}"
end
to_s() click to toggle source
# 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
Also aliased as: to_str
to_str()
Alias for: to_s

Private Instance Methods

arguments() click to toggle source
# File lib/stub_requests/dsl/method_definition.rb, line 61
def arguments
  @arguments ||= route_params.map { |param| "#{param}: #{param}" }.concat([+BLOCK_ARG]).join(", ")
end
keywords() click to toggle source
# File lib/stub_requests/dsl/method_definition.rb, line 57
def keywords
  @keywords ||= route_params.map { |param| "#{param}:" }.concat([+BLOCK_ARG]).join(", ")
end