Sha256: cd49e4e7db7e408404a3b00f4fa8b0ba8627023f51a75d587566ab47d55df591

Contents?: true

Size: 1.82 KB

Versions: 56

Compression:

Stored size: 1.82 KB

Contents

# frozen_string_literal: true

module Faraday
  module HelperMethods
    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods
      def features(*features)
        @features = features
      end

      def on_feature(name)
        yield if block_given? && feature?(name)
      end

      def feature?(name)
        if @features.nil?
          superclass.feature?(name) if superclass.respond_to?(:feature?)
        elsif @features.include?(name)
          true
        end
      end

      def method_with_body?(method)
        METHODS_WITH_BODY.include?(method.to_s)
      end
    end

    def ssl_mode?
      ENV['SSL'] == 'yes'
    end

    def normalize(url)
      Faraday::Utils::URI(url)
    end

    def with_default_uri_parser(parser)
      old_parser = Faraday::Utils.default_uri_parser
      begin
        Faraday::Utils.default_uri_parser = parser
        yield
      ensure
        Faraday::Utils.default_uri_parser = old_parser
      end
    end

    def with_env(new_env)
      old_env = {}

      new_env.each do |key, value|
        old_env[key] = ENV.fetch(key, false)
        ENV[key] = value
      end

      begin
        yield
      ensure
        old_env.each do |key, value|
          value == false ? ENV.delete(key) : ENV[key] = value
        end
      end
    end

    def with_env_proxy_disabled
      Faraday.ignore_env_proxy = true

      begin
        yield
      ensure
        Faraday.ignore_env_proxy = false
      end
    end

    def capture_warnings
      old = $stderr
      $stderr = StringIO.new
      begin
        yield
        $stderr.string
      ensure
        $stderr = old
      end
    end

    def method_with_body?(method)
      self.class.method_with_body?(method)
    end

    def big_string
      kb = 1024
      (32..126).map(&:chr).cycle.take(50 * kb).join
    end
  end
end

Version data entries

56 entries across 56 versions & 6 rubygems

Version Path
es_cli-0.1.0 vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/helper_methods.rb
faraday-2.12.2 spec/support/helper_methods.rb
faraday-2.12.1 spec/support/helper_methods.rb
moneykit-0.1.15 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
moneykit-0.1.14 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
faraday-2.12.0 spec/support/helper_methods.rb
faraday-2.11.0 spec/support/helper_methods.rb
moneykit-0.1.13 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
moneykit-0.1.12 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
moneykit-0.1.11 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
faraday-2.10.1 spec/support/helper_methods.rb
faraday-2.10.0 spec/support/helper_methods.rb
faraday-2.9.2 spec/support/helper_methods.rb
faraday-2.9.1 spec/support/helper_methods.rb
moneykit-0.1.10 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
moneykit-0.1.9 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
moneykit-0.1.6 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
moneykit-0.1.5 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
moneykit-0.1.4 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb
moneykit-0.1.3 vendor/bundle/ruby/3.2.0/gems/faraday-2.7.12/spec/support/helper_methods.rb