Class: ThriftRack::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/thrift_rack/server.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request = nil) ⇒ Server

Returns a new instance of Server.



3
4
5
# File 'lib/thrift_rack/server.rb', line 3

def initialize(request = nil)
  @_request = request
end

Class Method Details

.childrenObject



15
16
17
# File 'lib/thrift_rack/server.rb', line 15

def children
  @children ||= []
end

.inherited(subclass) ⇒ Object



8
9
10
11
12
13
# File 'lib/thrift_rack/server.rb', line 8

def inherited(subclass)
  warn "Your class should end with Server not it is #{subclass}" unless subclass.name.end_with?("Server")
  @children ||= []
  @children << subclass
  super
end

.inspectObject



19
20
21
22
# File 'lib/thrift_rack/server.rb', line 19

def inspect
  return super if self == ThriftRack::Server
  "#{self.name}(processor_class=#{self.processor_class},mount_path=#{self.mount_path})"
end

.mount_pathObject



37
38
39
40
41
# File 'lib/thrift_rack/server.rb', line 37

def mount_path
  return thrift_namespace unless /^[A-Z]/ =~ thrift_namespace
  path = thrift_namespace.scan(/[A-Z][a-z]*/).join("_").downcase
  "/#{path}"
end

.processor_classObject



24
25
26
27
28
29
30
31
# File 'lib/thrift_rack/server.rb', line 24

def processor_class
  promissory_class_name = "Thrift::#{thrift_namespace}::#{thrift_namespace}Service::Processor"
  if Kernel.const_defined?(promissory_class_name)
    Kernel.const_get(promissory_class_name)
  else
    raise "You should overwrite processor_class for #{self}"
  end
end

.protocol_factoryObject



33
34
35
# File 'lib/thrift_rack/server.rb', line 33

def protocol_factory
  Thrift::CompactProtocolFactory.new
end

.thrift_namespaceObject



43
44
45
# File 'lib/thrift_rack/server.rb', line 43

def thrift_namespace
  @thrift_namespace ||= self.name.scan(/[^\:]+$/).first.to_s.gsub(/Server$/, "").freeze
end