Sha256: 748d7a4fa5b6210ba177d16cd9058ebea9f15414c6309429ff72e621e9ee9ef0

Contents?: true

Size: 1.45 KB

Versions: 29

Compression:

Stored size: 1.45 KB

Contents

module Protobuf
  module Rpc
    class Env < Hash
      # Creates an accessor that simply sets and reads a key in the hash:
      #
      #   class Config < Hash
      #     hash_accessor :app
      #   end
      #
      #   config = Config.new
      #   config.app = Foo
      #   config[:app] #=> Foo
      #
      #   config[:app] = Bar
      #   config.app #=> Bar
      #
      def self.hash_accessor(*names) #:nodoc:
        names.each do |name|
          name_str = name.to_s.freeze

          define_method name do
            self[name_str]
          end

          define_method "#{name}=" do |value|
            self[name_str] = value
          end

          define_method "#{name}?" do
            !self[name_str].nil?
          end
        end
      end

      # TODO: Add extra info about the environment (i.e. variables) and other
      # information that might be useful
      hash_accessor :client_host,
                    :encoded_request,
                    :encoded_response,
                    :log_signature,
                    :method_name,
                    :request,
                    :request_type,
                    :response,
                    :response_type,
                    :rpc_method,
                    :rpc_service,
                    :service_name,
                    :worker_id

      def initialize(options = {})
        merge!(options)

        self['worker_id'] = ::Thread.current.object_id.to_s(16)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
protobuf-3.7.2.pre1 lib/protobuf/rpc/env.rb
protobuf-3.7.1 lib/protobuf/rpc/env.rb
protobuf-3.7.0 lib/protobuf/rpc/env.rb
protobuf-3.7.0.pre3 lib/protobuf/rpc/env.rb
protobuf-3.6.12 lib/protobuf/rpc/env.rb
protobuf-3.6.11 lib/protobuf/rpc/env.rb
protobuf-3.6.10 lib/protobuf/rpc/env.rb
protobuf-3.7.0.pre2 lib/protobuf/rpc/env.rb
protobuf-3.6.9 lib/protobuf/rpc/env.rb
protobuf-3.7.0.pre1 lib/protobuf/rpc/env.rb
protobuf-3.7.0.pre0 lib/protobuf/rpc/env.rb
protobuf-3.6.7 lib/protobuf/rpc/env.rb
protobuf-3.6.6 lib/protobuf/rpc/env.rb
protobuf-3.6.2 lib/protobuf/rpc/env.rb
protobuf-3.6.1 lib/protobuf/rpc/env.rb
protobuf-3.6.0 lib/protobuf/rpc/env.rb
protobuf-3.5.5 lib/protobuf/rpc/env.rb
protobuf-3.5.4 lib/protobuf/rpc/env.rb
protobuf-3.5.3 lib/protobuf/rpc/env.rb
protobuf-3.5.2 lib/protobuf/rpc/env.rb