ruby-rpc 0.0.2 → 0.0.4

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: e15f16471bfb364645be3fbb67a1cc1b8ddfd09c
4
- data.tar.gz: aa4b96bb27ddb55fcfdbb5defb79d27f01b924f8
3
+ metadata.gz: 2ce27f7b4567f8c071df02326001c60675481bf0
4
+ data.tar.gz: 124fb60c4135fad9bdb0dd0d7d9bd182135f1d19
5
5
  SHA512:
6
- metadata.gz: 8bff09f86d37ab61533b9c251c72200752d6d220948bc076bbc88c0e574ef76760242e3cda19805bd5bc0ac71b59dc91f8ff5dd13606e9c982e78216621776c8
7
- data.tar.gz: 6f1c2fb2beb048da8b0d3cb71722c4aec76ce680eefa2e1263646d3d3b6f9629c3f68ca85de0b1d4f824c1e68c4f01dd759c22e8ddd6337058f3ec35cf837a0e
6
+ metadata.gz: 4308faac5acec2680cb079c88a41bc8ecab72fbb8b764fc95e9fe1231ad74a9b0734268647a3cfee600a1ca0953a393172f441e9809e4a1b993af1206defb6d3
7
+ data.tar.gz: ec11e3b82be48e49fec6621231c15142a7180ef255bfdfd7104eec6a4b82bc16b7a69e40c51ded90af3ea238f42e96e8ab97ddfe56097884067a41c3ffb30155
data/.gitignore CHANGED
@@ -11,4 +11,5 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ *.gem
14
15
  mkmf.log
@@ -0,0 +1,11 @@
1
+ require 'ruby/rpc'
2
+ Ruby::RPC.enable client: true
3
+
4
+ Foobar
5
+ Foobar.included_modules
6
+ Foobar.bar
7
+
8
+ y = Foobar.new
9
+ y.inspect
10
+ y.foo
11
+ y.bar
@@ -5,22 +5,21 @@ require 'redis'
5
5
  require 'redis/connection/hiredis'
6
6
  require 'singleton'
7
7
  require 'redisrpc'
8
+ require 'ostruct'
8
9
 
9
10
  module Ruby
10
11
  module RPC
11
12
  class << self
12
- def enable
13
+ def enable params={}
14
+ Object.const_get('Ruby::RPC').const_set('SERVER',true) if params[:server]
15
+ Object.const_get('Ruby::RPC').const_set('CLIENT',true) if params[:client]
16
+ Object.const_get('Ruby::RPC').const_set('TIMEOUT',(params[:timeout]||5))
17
+ Object.const_get('Ruby::RPC').const_set('URL',(params[:url]||'redis://127.0.0.1'))
13
18
  require 'ruby/rpc/remote'
14
19
  require 'ruby/rpc/patch' if Object.const_defined? 'Ruby::RPC::CLIENT'
15
20
  end
16
- def server
17
- Object.const_get('Ruby::RPC').const_set('SERVER',true)
18
- end
19
- def client
20
- Object.const_get('Ruby::RPC').const_set('CLIENT',true)
21
- end
22
21
  def class_factory name
23
- Object.const_set(name,Class.new() { include Ruby::RPC::DeferCalls; extend Ruby::RPC::DeferCalls })
22
+ Object.const_set(name,Class.new(OpenStruct) { include Ruby::RPC::DeferCalls; extend Ruby::RPC::DeferCalls })
24
23
  end
25
24
  end
26
25
  end
@@ -0,0 +1,23 @@
1
+ module Ruby
2
+ module RPC
3
+ module DeferCalls
4
+ class << self
5
+ def method_missing method, *args, &block
6
+ puts "Class Method #{name} missing"
7
+ super unless Ruby::RPC::CLIENT
8
+ @client ||= RedisRPC::Client.new Redis.new(url:Ruby::RPC::URL,driver: :hiredis), self.to_s, timeout: Ruby::RPC::TIMEOUT
9
+ @client.send method, *args, &block
10
+ end
11
+ end
12
+ def initialize *args, &block
13
+ @channel = Ruby::RPC::Remote.build_remote self.class
14
+ super *args, &block
15
+ end
16
+ def method_missing method, *args, &block
17
+ super unless Ruby::RPC::CLIENT
18
+ @client ||= RedisRPC::Client.new Redis.new(url:Ruby::RPC::URL,driver: :hiredis), (@channel || self.to_s), timeout: Ruby::RPC::TIMEOUT
19
+ @client.send method, *args, &block
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ def Object.const_missing name
2
+ begin
3
+ if Ruby::RPC::Remote.remote_const_get name
4
+ return Ruby::RPC::class_factory name
5
+ end
6
+ rescue Exception => e
7
+ super name
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Ruby
2
+ module RPC
3
+ class Remote
4
+ extend Ruby::RPC::DeferCalls if Object.const_defined? 'Ruby::RPC::CLIENT'
5
+ include Ruby::RPC::RemoteCallable if Object.const_defined? 'Ruby::RPC::SERVER'
6
+ class << self
7
+ if Object.const_defined? 'Ruby::RPC::SERVER'
8
+ def remote_const_get name
9
+ const = Object.const_get name
10
+ const if const.included_modules.include? Ruby::RPC::RemoteCallable
11
+ end
12
+ def build_remote name, *args
13
+ Object.const_get(name).new *args
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Ruby
2
+ module RPC
3
+ module RemoteCallable
4
+ def initialize *args, &block
5
+ Thread.new do
6
+ RedisRPC::Server.new(Redis.new(url:ENV['redis_url'],driver: :hiredis), self, self).run
7
+ end
8
+ super *args, &block
9
+ end
10
+ def self.included base
11
+ Thread.new do
12
+ RedisRPC::Server.new(Redis.new(url:ENV['redis_url'],driver: :hiredis), base, base).run
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  module Ruby
2
2
  module RPC
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,20 @@
1
+ require 'ruby/rpc'
2
+ Ruby::RPC.enable server: true
3
+
4
+ puts "Defined Foobar"
5
+
6
+ class Foobar
7
+ include Ruby::RPC::RemoteCallable
8
+ def self.bar
9
+ :foo
10
+ end
11
+ def foo
12
+ :bar
13
+ end
14
+ end
15
+
16
+ puts "Waiting"
17
+
18
+ loop do
19
+ sleep 1
20
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - steigr
@@ -85,9 +85,15 @@ files:
85
85
  - LICENSE.txt
86
86
  - README.md
87
87
  - Rakefile
88
+ - client.rb
88
89
  - lib/ruby/rpc.rb
90
+ - lib/ruby/rpc/defer_calls.rb
91
+ - lib/ruby/rpc/patch.rb
92
+ - lib/ruby/rpc/remote.rb
93
+ - lib/ruby/rpc/remote_callable.rb
89
94
  - lib/ruby/rpc/version.rb
90
95
  - ruby-rpc.gemspec
96
+ - server.rb
91
97
  homepage: https://github.com/steigr/ruby-rpc
92
98
  licenses:
93
99
  - MIT