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 +4 -4
- data/.gitignore +1 -0
- data/client.rb +11 -0
- data/lib/ruby/rpc.rb +7 -8
- data/lib/ruby/rpc/defer_calls.rb +23 -0
- data/lib/ruby/rpc/patch.rb +9 -0
- data/lib/ruby/rpc/remote.rb +19 -0
- data/lib/ruby/rpc/remote_callable.rb +17 -0
- data/lib/ruby/rpc/version.rb +1 -1
- data/server.rb +20 -0
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ce27f7b4567f8c071df02326001c60675481bf0
|
4
|
+
data.tar.gz: 124fb60c4135fad9bdb0dd0d7d9bd182135f1d19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4308faac5acec2680cb079c88a41bc8ecab72fbb8b764fc95e9fe1231ad74a9b0734268647a3cfee600a1ca0953a393172f441e9809e4a1b993af1206defb6d3
|
7
|
+
data.tar.gz: ec11e3b82be48e49fec6621231c15142a7180ef255bfdfd7104eec6a4b82bc16b7a69e40c51ded90af3ea238f42e96e8ab97ddfe56097884067a41c3ffb30155
|
data/client.rb
ADDED
data/lib/ruby/rpc.rb
CHANGED
@@ -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,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
|
data/lib/ruby/rpc/version.rb
CHANGED
data/server.rb
ADDED
@@ -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.
|
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
|