DRbServe 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/example/test.rb +24 -0
- data/lib/DRbServe.rb +72 -0
- data/test/test_helper.rb +9 -0
- metadata +59 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Miguel Vazquez
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= DRbServe
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but
|
13
|
+
bump version in a commit by itself I can ignore when I pull)
|
14
|
+
* Send me a pull request. Bonus points for topic branches.
|
15
|
+
|
16
|
+
== Copyright
|
17
|
+
|
18
|
+
Copyright (c) 2009 Miguel Vazquez. See LICENSE for details.
|
data/example/test.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
$: << File.join(File.dirname(File.dirname(__FILE__)),'lib')
|
2
|
+
|
3
|
+
require 'DRbServe'
|
4
|
+
|
5
|
+
# Load this file once and them open a irb session. Try loading the module, you
|
6
|
+
# will be using DRb to connect to the server
|
7
|
+
|
8
|
+
module Test
|
9
|
+
def self.a
|
10
|
+
@counter ||= 0
|
11
|
+
puts @counter += 1
|
12
|
+
@counter
|
13
|
+
end
|
14
|
+
|
15
|
+
extend DRbServe
|
16
|
+
serve :a
|
17
|
+
hook
|
18
|
+
end
|
19
|
+
|
20
|
+
if __FILE__ == $0
|
21
|
+
Test.start_server
|
22
|
+
end
|
23
|
+
|
24
|
+
|
data/lib/DRbServe.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'drb'
|
2
|
+
require 'fileutils'
|
3
|
+
module DRbServe
|
4
|
+
|
5
|
+
def uri_filename=(filename)
|
6
|
+
@uri_filename = filename
|
7
|
+
end
|
8
|
+
|
9
|
+
def uri_filename
|
10
|
+
@uri_filename ||= File.join('/tmp', "DRbServe" + self.to_s + ".uri")
|
11
|
+
@uri_filename
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def uri=(uri)
|
16
|
+
puts "Saving #{ uri } in #{ self.uri_filename }"
|
17
|
+
FileUtils.mkdir_p FileUtils.dirname(uri_filename) unless File.exist? File.dirname(uri_filename)
|
18
|
+
fout = File.open(uri_filename,'w')
|
19
|
+
fout.puts uri
|
20
|
+
fout.close
|
21
|
+
end
|
22
|
+
|
23
|
+
def uri
|
24
|
+
File.open(uri_filename).read
|
25
|
+
end
|
26
|
+
|
27
|
+
def start_server
|
28
|
+
if Class === self
|
29
|
+
o = self.new
|
30
|
+
else
|
31
|
+
o = self
|
32
|
+
end
|
33
|
+
|
34
|
+
class << o
|
35
|
+
def alive
|
36
|
+
true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
DRb.start_service nil, o
|
41
|
+
self.uri= DRb.uri
|
42
|
+
puts uri
|
43
|
+
DRb.thread.join
|
44
|
+
end
|
45
|
+
|
46
|
+
def hook
|
47
|
+
if File.exist? uri_filename
|
48
|
+
begin
|
49
|
+
@remote = DRbObject.new(nil, uri)
|
50
|
+
puts "Connected to #{ uri }" if @remote.alive
|
51
|
+
@served ||=[]
|
52
|
+
@served.each{|method_name|
|
53
|
+
class << self; self; end.instance_eval{
|
54
|
+
define_method(method_name,
|
55
|
+
proc{|*args|
|
56
|
+
@remote.send(method_name, *args)
|
57
|
+
})
|
58
|
+
}
|
59
|
+
}
|
60
|
+
rescue
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def serve(method)
|
66
|
+
@served ||= []
|
67
|
+
@served << method
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: DRbServe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Miguel Vazquez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-29 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: One process loads the module and serves some methods unsing DRb. Other processes mangle those methods to hook up with the DRb server
|
17
|
+
email: miguel.vazquez@fdi.ucm.es
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- example/test.rb
|
27
|
+
- lib/DRbServe.rb
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/mikisvaz/DRbServe
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --charset=UTF-8
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: "0"
|
44
|
+
version:
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
requirements: []
|
52
|
+
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.3.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: Share a module between processes using DRb
|
58
|
+
test_files:
|
59
|
+
- test/test_helper.rb
|