Module: Thrifter

Defined in:
lib/thrifter.rb,
lib/thrifter/version.rb,
lib/thrifter/extensions/ping.rb,
lib/thrifter/instrumented_pool.rb,
lib/thrifter/extensions/queueing.rb,
lib/thrifter/extensions/retriable.rb,
lib/thrifter/middleware/validation.rb,
lib/thrifter/middleware/rpc_metrics.rb,
lib/thrifter/middleware/client_metrics.rb,
lib/thrifter/middleware/error_wrapping.rb

Defined Under Namespace

Modules: Ping, Queueing, Retry Classes: Client, ClientMetrics, Configuration, ErrorWrapping, InstrumentedPool, MiddlewareStack, NullStatsd, RPC, RpcMetrics, Validation

Constant Summary collapse

ClientError =
Tnt.boom do |ex|
  "#{ex.class}: #{ex.message}"
end
RESERVED_METHODS =
[
  :send_message,
  :send_oneway_message,
  :send_message_args
]
VERSION =
"1.1.0"
RetryError =
Tnt.boom do |count, rpc, exception|
  "#{rpc} RPC unsuccessful after #{count} times. #{exception.class}: #{exception.message}"
end
ValidationError =
Tnt.boom do |rpc, ex|
  "Invalid data in RPC #{rpc.name}! #{ex.message}"
end

Class Method Summary collapse

Class Method Details

.build(client_class, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/thrifter.rb', line 55

def build(client_class, &block)
  rpcs = client_class.instance_methods.each_with_object([ ]) do |method_name, rpcs|
    next if RESERVED_METHODS.include? method_name
    next unless method_name =~ /^send_(?<rpc>.+)$/
    rpcs << Regexp.last_match[:rpc].to_sym
  end

  rpcs.freeze

  Class.new Client do
    rpcs.each do |rpc_name|
      define_method rpc_name do |*args|
        invoke RPC.new(rpc_name, args)
      end
    end

    class_eval(&block) if block

    private

    define_method :rpcs do
      rpcs
    end

    define_method :client_class do
      client_class
    end
  end
end