Sha256: 3d680f001e07638b1c1833b2122d33dc426fd3738f58571afe65b38da1e78872

Contents?: true

Size: 1.91 KB

Versions: 13

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true
module Ethon
  class Easy
    # This module contains the logic to prepare and perform
    # an easy.
    module Operations
      
      class PointerHelper
        class<<self
          def synchronize( &block )
            (@mutex ||= Mutex.new).synchronize( &block )
          end

          def release( pointer )
            synchronize { Curl.easy_cleanup pointer }
          end
        end
        synchronize{}
      end

      # Returns a pointer to the curl easy handle.
      #
      # @example Return the handle.
      #   easy.handle
      #
      # @return [ FFI::Pointer ] A pointer to the curl easy handle.
      def handle
        @handle ||= FFI::AutoPointer.new(Curl.easy_init, PointerHelper.method(:release) )
      end

      # Sets a pointer to the curl easy handle.
      # @param [ ::FFI::Pointer ] Easy handle that will be assigned.
      def handle=(h)
        @handle = h
      end

      # Perform the easy request.
      #
      # @example Perform the request.
      #   easy.perform
      #
      # @return [ Integer ] The return code.
      def perform
        @return_code = Curl.easy_perform(handle)
        if Ethon.logger.debug?
          Ethon.logger.debug { "ETHON: performed #{log_inspect}" }
        end
        complete
        @return_code
      end

      # Clean up the easy.
      #
      # @example Perform clean up.
      #   easy.cleanup
      #
      # @return the result of the free which is nil
      def cleanup
        handle.free
      end

      # Prepare the easy. Options, headers and callbacks
      # were set.
      #
      # @example Prepare easy.
      #   easy.prepare
      #
      # @deprecated It is no longer necessary to call prepare.
      def prepare
        Ethon.logger.warn(
          "ETHON: It is no longer necessary to call "+
          "Easy#prepare. It's going to be removed "+
          "in future versions."
        )
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 5 rubygems

Version Path
svix-0.53.1 vendor/bundle/ruby/2.7.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
svix-0.53.0 vendor/bundle/ruby/2.7.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ory-keto-client-0.7.0.alpha0 vendor/bundle/ruby/2.5.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ory-kratos-client-0.7.6.alpha7 vendor/bundle/ruby/2.5.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ory-kratos-client-0.7.6.alpha6 vendor/bundle/ruby/2.5.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ory-kratos-client-0.7.6.alpha5 vendor/bundle/ruby/2.5.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ory-kratos-client-0.7.6.alpha4 vendor/bundle/ruby/2.5.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ory-kratos-client-0.7.6.alpha3 vendor/bundle/ruby/2.5.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ory-kratos-client-0.7.6.alpha1 vendor/bundle/ruby/2.5.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ory-kratos-client-0.7.5.alpha2 vendor/bundle/ruby/2.5.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
cloudsmith-api-0.57.1 vendor/bundle/ruby/2.6.0/gems/ethon-0.14.0/lib/ethon/easy/operations.rb
ethon-0.14.0 lib/ethon/easy/operations.rb
ethon-0.13.0 lib/ethon/easy/operations.rb