Sha256: aef48fd05105244c1d9c4662196ca570193ab5d424051ef83fe8efef6b2dd07c

Contents?: true

Size: 1.19 KB

Versions: 8

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module StubRequests
  class DSL
    #
    # Class DefineMethod defines helper methods for stubbed endpoints
    #
    # @author Mikael Henriksson <mikael@zoolutions.se>
    # @since 0.1.4
    #
    class DefineMethod
      #
      # @!attribute [r] definition
      #   @return [MethodDefinition] the method definition
      attr_reader :definition
      #
      # @!attribute [r] receiver
      #   @return [Module] the receiver of the method definition
      attr_reader :receiver

      #
      # Initialize a new instance of DefineMethod
      #
      #
      # @param [MethodDefinition] definition the method definition
      # @param [Module] receiver the receiver of the method definition
      #
      def initialize(definition, receiver)
        @receiver   = receiver
        @definition = definition
      end

      #
      # Define the {MethodDefinition#to_s} on the receiver
      #
      #
      # @return [void]
      #
      def define
        Docile.dsl_eval(receiver) do
          silence_redefinition_of_method(definition.name)
          module_eval <<~METHOD, __FILE__, __LINE__ + 1
            #{definition}
          METHOD
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stub_requests-0.1.11 lib/stub_requests/dsl/define_method.rb
stub_requests-0.1.10 lib/stub_requests/dsl/define_method.rb
stub_requests-0.1.9 lib/stub_requests/dsl/define_method.rb
stub_requests-0.1.8 lib/stub_requests/dsl/define_method.rb
stub_requests-0.1.7 lib/stub_requests/dsl/define_method.rb
stub_requests-0.1.6 lib/stub_requests/dsl/define_method.rb
stub_requests-0.1.5 lib/stub_requests/dsl/define_method.rb
stub_requests-0.1.4 lib/stub_requests/dsl/define_method.rb