Sha256: 4094c10a943ca64eb56d1ec1343d62715a7c89ea51959603c854c57793b78cd5
Contents?: true
Size: 1.62 KB
Versions: 2
Compression:
Stored size: 1.62 KB
Contents
# frozen_string_literal: true module StubRequests class DSL # # Class DefineMethod generates method definition for a stubbed endpoint # # @author Mikael Henriksson <mikael@zoolutions.se> # @since 0.1.4 # class MethodDefinition # # @return [String] BLOCK_ARG = "&block" # # @!attribute [r] endpoint_id # @return [Symbol] the id of a registered endpoint attr_reader :endpoint_id # # @!attribute [r] route_params # @return [Array<Symbol>] the URI parameters for the endpoint attr_reader :route_params # # 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 # def initialize(endpoint_id, route_params) @endpoint_id = endpoint_id @route_params = route_params end # # The name of this method # # # @return [String] a string prefixed with stub_, `"stub_documents_show"` # def name @name ||= "stub_#{endpoint_id}" end def to_s <<~METHOD def #{name}(#{keywords}) StubRequests.stub_endpoint(:#{endpoint_id}, #{arguments}) end METHOD end alias to_str to_s private def keywords @keywords ||= route_params.map { |param| "#{param}:" }.concat([+BLOCK_ARG]).join(", ") end def arguments @arguments ||= route_params.map { |param| "#{param}: #{param}" }.concat([+BLOCK_ARG]).join(", ") end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stub_requests-0.1.11 | lib/stub_requests/dsl/method_definition.rb |
stub_requests-0.1.10 | lib/stub_requests/dsl/method_definition.rb |