Sha256: 5630095d9f7c2cc51a77eead8018e4f36d674067de295b37c7eaa2f840461c39

Contents?: true

Size: 1.46 KB

Versions: 23

Compression:

Stored size: 1.46 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|
          class_eval <<-METHOD, __FILE__, __LINE__ + 1
            def #{name}
              self['#{name}']
            end

            def #{name}=(value)
              self['#{name}'] = value
            end

            def #{name}?
              ! self['#{name}'].nil?
            end
          METHOD
        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

23 entries across 23 versions & 2 rubygems

Version Path
protobuffy-3.5.1 lib/protobuf/rpc/env.rb
protobuffy-3.4.0 lib/protobuf/rpc/env.rb
protobuffy-3.3.0 lib/protobuf/rpc/env.rb
protobuffy-3.2.0 lib/protobuf/rpc/env.rb
protobuffy-3.1.0 lib/protobuf/rpc/env.rb
protobuf-3.3.6 lib/protobuf/rpc/env.rb
protobuf-3.3.5 lib/protobuf/rpc/env.rb
protobuf-3.3.4 lib/protobuf/rpc/env.rb
protobuf-3.3.3 lib/protobuf/rpc/env.rb
protobuf-3.3.2 lib/protobuf/rpc/env.rb
protobuf-3.3.1 lib/protobuf/rpc/env.rb
protobuf-3.3.0 lib/protobuf/rpc/env.rb
protobuf-3.2.1 lib/protobuf/rpc/env.rb
protobuf-3.2.0 lib/protobuf/rpc/env.rb
protobuf-3.1.0 lib/protobuf/rpc/env.rb
protobuf-3.0.5 lib/protobuf/rpc/env.rb
protobuf-3.0.4 lib/protobuf/rpc/env.rb
protobuf-3.0.3 lib/protobuf/rpc/env.rb
protobuf-3.0.2 lib/protobuf/rpc/env.rb
protobuf-3.0.1 lib/protobuf/rpc/env.rb