Sha256: 80503f8dab07f0288b3b99496012c98a4b7602faa2972685f429bde708516461

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

module Thrift
  class StructDefinition
    attr_reader :klass

    def initialize(klass)
      @klass = klass
    end

    def namespace
      @klass::NAMESPACE
    end

    def name
      @klass::NAME
    end

    def struct_type
      "#{namespace}.#{name}"
    end
  end

  class ServiceDefinition < StructDefinition
    attr_reader :klass

    def initialize(klass)
      @klass = klass
    end

    def client_class
      @klass::Client
    end

    def processor_class
      @klass::Processor
    end

    def namespace
      @klass::NAMESPACE
    end

    def service
      @klass::SERVICE
    end

    def service_type
      "#{namespace}.#{service}"
    end
  end

  STRUCT_DEFINITIONS = {}
  SERVICE_DEFINITIONS = {}

  class << self
    def register_struct_type(klass)
      definition = StructDefinition.new(klass)
      STRUCT_DEFINITIONS[definition.struct_type] = definition
    end

    def register_service_type(klass)
      definition = ServiceDefinition.new(klass)
      SERVICE_DEFINITIONS[definition.service_type] = definition
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
upfluence-thrift-2.4.4 lib/thrift/definition.rb
upfluence-thrift-2.3.1 lib/thrift/definition.rb
upfluence-thrift-2.3.0 lib/thrift/definition.rb
upfluence-thrift-2.2.0 lib/thrift/definition.rb