thrift_client 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ v0.1.3. Define methods explicitly.
3
+
2
4
  v0.1.2. Support default responses.
3
5
 
4
6
  v0.1.1. Support server_retry_period.
data/lib/thrift_client.rb CHANGED
@@ -52,7 +52,24 @@ Valid optional parameters are:
52
52
 
53
53
  @set_timeout = @options[:transport].instance_methods.include?("timeout=")
54
54
  @live_server_list = @server_list.dup
55
- @last_retry = Time.now
55
+ @last_retry = Time.now
56
+
57
+ @client_class.instance_methods.each do |method_name|
58
+ if method_name =~ /^recv_(.*)$/
59
+ instance_eval("def #{$1}(*args); proxy(:'#{$1}', *args); end")
60
+ end
61
+ end
62
+ end
63
+
64
+ # Force the client to connect to the server.
65
+ def connect!
66
+ server = next_server.to_s.split(":")
67
+ raise ArgumentError, 'Servers must be in the form "host:port"' if server.size != 2
68
+
69
+ @transport = @options[:transport].new(
70
+ Thrift::Socket.new(server.first, server.last.to_i, @options[:timeouts].default))
71
+ @transport.open
72
+ @client = @client_class.new(@options[:protocol].new(@transport, false))
56
73
  end
57
74
 
58
75
  # Force the client to disconnect from the server.
@@ -63,7 +80,7 @@ Valid optional parameters are:
63
80
 
64
81
  private
65
82
 
66
- def method_missing(method_name, *args)
83
+ def proxy(method_name, *args)
67
84
  connect! unless @client
68
85
  set_timeout!(method_name) if @set_timeout
69
86
  @client.send(method_name, *args)
@@ -87,16 +104,6 @@ Valid optional parameters are:
87
104
  @options[:defaults][method_name.to_sym]
88
105
  end
89
106
 
90
- def connect!
91
- server = next_server.to_s.split(":")
92
- raise ArgumentError, 'Servers must be in the form "host:port"' if server.size != 2
93
-
94
- @transport = @options[:transport].new(
95
- Thrift::Socket.new(server.first, server.last.to_i, @options[:timeouts].default))
96
- @transport.open
97
- @client = @client_class.new(@options[:protocol].new(@transport, false))
98
- end
99
-
100
107
  def next_server
101
108
  if @live_server_list.empty?
102
109
  if @options[:server_retry_period] and Time.now < @last_retry + @options[:server_retry_period]
@@ -106,5 +113,5 @@ Valid optional parameters are:
106
113
  @live_server_list = @server_list.dup
107
114
  end
108
115
  @live_server_list.pop
109
- end
116
+ end
110
117
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{thrift_client}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Evan Weaver"]
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrift_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Weaver
metadata.gz.sig CHANGED
@@ -1,3 +1 @@
1
- ���3�f��VQk��K��(N�D�)��#v��|N{O6��������� �;n!�_���^�޻�/���i
2
- �*h4�3N��[s6���0�P1���P~R?���vf�h�����O.n�)��<Q}}Jċ���%��b�~��i�V+ȝ��@����=B0�f]�JU��8H����/&��'�yA�L��唄�(�Z*�f��;�gnk� B,=��� ���
3
- nL��,��O5�6:�#�ި
1
+ z���]�H7���=_�i~���Pl:Em�P:�ގ ���?�2U�ix���a�qyY����\B���S�R#e0�a��h0{"��Q t��JJ�,��^��*+yI}�2�����׫����{<�9FV�MV�؁�c&��-��|�w�Jk -�d��� � ���$Ҿ�/�q�������η D�S2���.����x��<�.X�������lUн�����f�\"�=IC������fgMW