thrifter 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4d4d2c07c4f438c528cbee2fb79eaaad32d492e0
4
- data.tar.gz: 04118a2ca3fdc79444b6454ab63897344ab09ae2
3
+ metadata.gz: f749536c8bf5a2560c17986f6ef8a38828aedc22
4
+ data.tar.gz: 3a1e08e6e213162ac77ceffb70c329bfa7ce0756
5
5
  SHA512:
6
- metadata.gz: 57afa5cab7442e4af1bb49cc35b856ebadc9dd94fe83cb36daf069042ad8ac93e368793b376410e1da3539adbd87cbf3db0a809b957279a9e6c7b9971db9b0e7
7
- data.tar.gz: d99656e443fbf32b2a16fc805d211d92549b06e69b58480961c6f823775ed2071a0afb6ea755f8d3b505b911ccc2e36f56881b7495737d786e4a7d392e2f35a0
6
+ metadata.gz: 6429f24abd079c31a99e0701dbe051d9f63716776175028a56c9a65526486fc606cdcc8e107ccffcad77ae9cc75c2c52c84dbe2f24fb611f77cd5cb105f48686
7
+ data.tar.gz: 4344478d6dc7553594d54b89f274ad4854e196e01c20d36fc219fbc356113068282fa6e113611ced192e6add67b693b85706f5535cfa82b70ddaf377e0193a21
@@ -12,27 +12,37 @@ module Thrifter
12
12
  # other structure. This is why the method has so many arguments.
13
13
  # Sidekik-thrift_arguments will correctly pick up any complex
14
14
  # type in the splat and handle serialization/deserialization
15
- def perform(klass, rpc_name, *rpc_args)
15
+ def perform(klass, method_name, *args)
16
16
  client = klass.constantize.new
17
- client.send rpc_name, *rpc_args
17
+ client.send method_name, *args
18
18
  end
19
19
  end
20
20
 
21
- class Proxy
22
- def initialize(klass, rpcs)
23
- rpcs.each do |name|
24
- define_singleton_method name do |*args|
25
- job_args = [ klass.to_s, name ].concat(args)
26
- Job.perform_async(*job_args)
27
- end
21
+ class Proxy < BasicObject
22
+ def initialize(target)
23
+ @target = target
24
+ end
25
+
26
+ def method_missing(name, *args, &block)
27
+ if target.respond_to? name
28
+ job_args = [ target.class.to_s, name ].concat(args)
29
+ Job.perform_async(*job_args)
30
+ else
31
+ super
28
32
  end
29
33
  end
34
+
35
+ private
36
+
37
+ def target
38
+ @target
39
+ end
30
40
  end
31
41
 
32
42
  def queued
33
- Proxy.new(self.class, rpcs).tap do |proxy|
34
- yield proxy if block_given?
35
- end
43
+ proxy = Proxy.new self
44
+ yield proxy if block_given?
45
+ proxy
36
46
  end
37
47
  end
38
48
  end
@@ -16,21 +16,19 @@ module Thrifter
16
16
  Errno::ETIMEDOUT
17
17
  ]
18
18
 
19
- class Proxy
19
+ class Proxy < BasicObject
20
20
  attr_reader :tries, :interval, :client
21
21
 
22
- def initialize(client, tries, interval, rpcs)
22
+ def initialize(client, tries, interval)
23
23
  @client, @tries, @interval = client, tries, interval
24
-
25
- rpcs.each do |name|
26
- define_singleton_method name do |*args|
27
- invoke_with_retry(name, *args)
28
- end
29
- end
30
24
  end
31
25
 
32
26
  private
33
27
 
28
+ def method_missing(name, *args)
29
+ invoke_with_retry(name, *args)
30
+ end
31
+
34
32
  def invoke_with_retry(name, *args)
35
33
  counter = 0
36
34
 
@@ -49,9 +47,9 @@ module Thrifter
49
47
  end
50
48
 
51
49
  def with_retry(tries: 5, interval: 0.01)
52
- Proxy.new(self, tries, interval, rpcs).tap do |proxy|
53
- yield proxy if block_given?
54
- end
50
+ proxy = Proxy.new self, tries, interval
51
+ yield proxy if block_given?
52
+ proxy
55
53
  end
56
54
  end
57
55
  end
@@ -1,3 +1,3 @@
1
1
  module Thrifter
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -12,6 +12,10 @@ class QueuingTest < MiniTest::Unit::TestCase
12
12
  include Thrifter::Queueing
13
13
 
14
14
  self.config.uri = 'tcp://localhost:9090'
15
+
16
+ def custom_echo
17
+ echo TestMessage.new(message: 'custom')
18
+ end
15
19
  end
16
20
 
17
21
  def queue
@@ -26,7 +30,7 @@ class QueuingTest < MiniTest::Unit::TestCase
26
30
  queue.clear
27
31
  end
28
32
 
29
- def test_sends_rpcs_with_sidekiq
33
+ def test_queues_methods_with_sidekiq
30
34
  client = QueuedClient.new
31
35
 
32
36
  message = TestMessage.new message: 'echo'
@@ -62,7 +66,7 @@ class QueuingTest < MiniTest::Unit::TestCase
62
66
  refute jobs.empty?, 'Nothing enqueued'
63
67
  end
64
68
 
65
- def test_fails_if_given_rpc_name
69
+ def test_fails_if_given_unknown_method
66
70
  client = QueuedClient.new
67
71
  message = TestMessage.new message: 'echo'
68
72
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thrifter
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
  - ahawkins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-01 00:00:00.000000000 Z
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thrift