Sha256: 65f231de83d764196b84b52f1df9c8a78938f67df924d34e0cfd9aa9c371df03

Contents?: true

Size: 928 Bytes

Versions: 6

Compression:

Stored size: 928 Bytes

Contents

module Ethon
  class Easy
    class Mirror
      attr_reader :options
      alias_method :to_hash, :options

      def self.informations_to_mirror
        Informations::AVAILABLE_INFORMATIONS.keys +
          [:return_code, :response_headers, :response_body, :debug_info]
      end

      def self.informations_to_log
        [:effective_url, :response_code, :return_code, :total_time]
      end

      def self.from_easy(easy)
        options = {}
        informations_to_mirror.each do |info|
          options[info] = easy.send(info)
        end
        new(options)
      end

      def initialize(options = {})
        @options = options
      end

      def log_informations
        Hash[*self.class.informations_to_log.map do |info|
          [info, options[info]]
        end.flatten]
      end

      informations_to_mirror.each do |info|
        eval %Q|def #{info}; options[#{info}]; end|
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/ethon-0.8.0/lib/ethon/easy/mirror.rb
ethon-0.8.0 lib/ethon/easy/mirror.rb
ethon-0.7.4 lib/ethon/easy/mirror.rb
ethon-0.7.3 lib/ethon/easy/mirror.rb
ethon-0.7.2 lib/ethon/easy/mirror.rb
ethon-0.7.1 lib/ethon/easy/mirror.rb