ruby-proxy 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,9 @@
1
+ require 'ruby_proxy/server'
2
+
3
+ RubyProxy::DRbServer.ip = ARGV[0] unless ARGV[0].nil?
4
+ RubyProxy::DRbServer.port = ARGV[1] unless ARGV[1].nil?
5
+
6
+ puts "start server ip: #{RubyProxy::DRbServer.ip}"
7
+ puts "start server port:#{RubyProxy::DRbServer.port}"
8
+ #~ Dir.chdir ARGV[2] unless ARGV[2].nil?
9
+ RubyProxy::DRbServer.start_service
@@ -6,7 +6,6 @@ require 'logger'
6
6
 
7
7
  module ATU
8
8
 
9
- #require redefine
10
9
  class << self
11
10
  alias require_old require
12
11
 
@@ -24,6 +23,11 @@ module ATU
24
23
  def []=(arg,var)
25
24
  RubyProxy::DRbClient.proxy_global_set(arg,var)
26
25
  end
26
+
27
+ #load path
28
+ def <<(path)
29
+ RubyProxy::DRbClient.add_load_path(path)
30
+ end
27
31
  end
28
32
 
29
33
  #entry
@@ -157,8 +161,8 @@ module RubyProxy
157
161
  class <<self
158
162
  def client
159
163
  begin
160
- stop_service if @client.nil?
161
- start_service if @client.nil?
164
+ stop_service if @client.nil? and Config.autostart
165
+ start_service if @client.nil? and Config.autostart
162
166
  connect_addr = "druby://#{Config.ip}:#{Config.port}"
163
167
  @client ||= DRbObject.new(nil,connect_addr)
164
168
  rescue DRb::DRbConnError
@@ -187,6 +191,11 @@ module RubyProxy
187
191
  client.proxy_global_set(arg,var)
188
192
  end
189
193
 
194
+ def add_load_path(path)
195
+ #path = File.expand_path(path)
196
+ client.add_load_path(path)
197
+ end
198
+
190
199
  # not use it later
191
200
  def start_service(t=10)
192
201
  message = nil
@@ -199,6 +208,7 @@ module RubyProxy
199
208
  #~ end
200
209
  #~ @server_thread.abort_on_exception = true
201
210
  wait_until_server_start_time(t)
211
+ do_at_exit if Config.autostart
202
212
  end
203
213
 
204
214
  def start_command
@@ -208,7 +218,7 @@ module RubyProxy
208
218
  end
209
219
 
210
220
  def stop_service(t=5)
211
- TCPSocket.new(Config.ip,Config.port)
221
+ #TCPSocket.new(Config.ip,Config.port)
212
222
  @client ||= DRbObject.new(nil,"druby://#{Config.ip}:#{Config.port}")
213
223
  @client.stop_proxy
214
224
  sleep 1
@@ -225,7 +235,6 @@ module RubyProxy
225
235
  #~ raise CannotStartServer, "" unless @server_thread.alive?
226
236
  TCPSocket.new(Config.ip,Config.port)
227
237
  @@logger.info "server is starting"
228
- #do_at_exit
229
238
  return true
230
239
  rescue Exception
231
240
  sleep 1
@@ -2,8 +2,9 @@ module RubyProxy
2
2
  class Config
3
3
  @config = {
4
4
  :ip => '127.0.0.1',
5
- :port=> 8000,
6
- :command => 'ruby'
5
+ :port=> 8889,
6
+ :command => 'ruby',
7
+ :autostart => true,
7
8
  }
8
9
  class <<self
9
10
  def ip
@@ -29,6 +30,13 @@ module RubyProxy
29
30
  def command=(command)
30
31
  @config[:command] = command
31
32
  end
33
+
34
+ def autostart
35
+ @config[:autostart]
36
+ end
37
+ def autostart=(bool)
38
+ @config[:autostart] = bool
39
+ end
32
40
  end
33
41
  end
34
42
  end
@@ -28,6 +28,10 @@ module RubyProxy
28
28
  def self.proxy_global_get(arg)
29
29
  ProxyGlobalSet.get(arg)
30
30
  end
31
+
32
+ def self.add_load_path(path)
33
+ ProxyGlobalSet.add("$LOAD_PATH",path)
34
+ end
31
35
 
32
36
  def self.proxy_type(klass_name)
33
37
  return proxy_const_get(klass_name).class.to_s
@@ -10,6 +10,13 @@ module RubyProxy
10
10
  eval("#{arg} = #{value}")
11
11
  end
12
12
 
13
+ # add to $LOAD_PATH
14
+ def add(arg,value)
15
+ arg = convert_to_global(arg)
16
+ Logger.info "global add: #{arg} << #{value}"
17
+ eval("#{arg} << \"#{value}\"")
18
+ end
19
+
13
20
  def get(arg)
14
21
  arg = convert_to_global(arg)
15
22
  Logger.info "global get: #{arg}"
@@ -7,12 +7,16 @@ require 'ruby_proxy/proxy'
7
7
  require 'drb/timeridconv'
8
8
  module RubyProxy
9
9
  class DRbServer
10
+ @ip = Config.ip
11
+ @port = Config.port
12
+
10
13
  class << self
11
14
  attr_accessor :ip,:port
12
15
  end
16
+
13
17
  def self.start_service
14
18
  DRb.install_id_conv(DRb::TimerIdConv.new)
15
- DRb.start_service("druby://#{Config.ip}:#{Config.port}",Proxy)
19
+ DRb.start_service("druby://#{ip}:#{port}",Proxy)
16
20
  #~ trap("INT") { DRb.stop_service }
17
21
  # for ruby1.9
18
22
  begin
@@ -1,3 +1,3 @@
1
1
  module RubyProxy
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -1,3 +1,4 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
1
2
  require 'setup'
2
3
 
3
- $all_tests.each { |f| require f }
4
+ $all_tests.each { |f| require f }
@@ -6,4 +6,6 @@ require 'test/unit'
6
6
 
7
7
  require 'ruby_proxy'
8
8
 
9
+ #RubyProxy::Config.autostart = false
10
+
9
11
  $all_tests = Dir['test_*.rb']
@@ -7,7 +7,7 @@ class TestConfig < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_config_default
10
- assert_equal(8000, @config.port)
10
+ assert_equal(8889, @config.port)
11
11
  assert_equal('127.0.0.1', @config.ip)
12
12
  end
13
13
 
@@ -12,6 +12,7 @@ end
12
12
  class TestDrbProxy < Test::Unit::TestCase
13
13
 
14
14
  def setup
15
+ ATU << File.dirname(__FILE__)
15
16
  ATU::require 'support/atu/hello'
16
17
  end
17
18
 
@@ -17,4 +17,11 @@ class TestGlobalVar < Test::Unit::TestCase
17
17
  ATU["HELLO"] = 10
18
18
  assert_equal(10, ATU["HELLO"])
19
19
  end
20
+
21
+ def test_global_add_ok
22
+ load_path = ATU["$LOAD_PATH"]
23
+ load_path << File.dirname(__FILE__)
24
+ ATU << File.dirname(__FILE__)
25
+ assert_equal(load_path, ATU["$LOAD_PATH"])
26
+ end
20
27
  end
@@ -1,8 +1,11 @@
1
1
  require 'setup'
2
2
 
3
- RubyProxy::Config.command = "/home/windy/.rvm/rubies/jruby-1.6.7/bin/ruby"
3
+ #RubyProxy::Config.command = "/home/windy/.rvm/rubies/jruby-1.6.7/bin/ruby"
4
4
 
5
5
  class TestAtuLoad < Test::Unit::TestCase
6
+ def setup
7
+ ATU << File.dirname(__FILE__)
8
+ end
6
9
  def test_load_ok
7
10
  assert_nothing_raised {
8
11
  ATU.require 'support/atu/hello.rb'
metadata CHANGED
@@ -1,32 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ruby-proxy
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - yafei Lee
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-04-21 00:00:00 Z
12
+ date: 2012-04-24 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Ruby Proxy for two or more ruby processes.
22
15
  email: lyfi2003@gmail.com
23
- executables: []
24
-
16
+ executables:
17
+ - ruby_proxy_server
25
18
  extensions: []
26
-
27
19
  extra_rdoc_files: []
28
-
29
- files:
20
+ files:
30
21
  - lib/ruby_proxy/config.rb
31
22
  - lib/ruby_proxy/client.rb
32
23
  - lib/ruby_proxy/exceptions.rb
@@ -41,55 +32,48 @@ files:
41
32
  - lib/ext/drb_ext.rb
42
33
  - unittests/test_drb_proxy.rb
43
34
  - unittests/test_config.rb
44
- - unittests/test_gloabal_var.rb
45
35
  - unittests/all_tests.rb
46
36
  - unittests/support/config.yml
47
37
  - unittests/support/image/search.png
48
38
  - unittests/support/image/start.png
49
39
  - unittests/support/atu/hello.rb
50
- - unittests/test_atu_require.rb
40
+ - unittests/test_global_var.rb
41
+ - unittests/test_require.rb
51
42
  - unittests/setup.rb
43
+ - !binary |-
44
+ YmluL3J1YnlfcHJveHlfc2VydmVy
52
45
  homepage: https://github.com/windy/ruby_proxy
53
46
  licenses: []
54
-
55
47
  post_install_message:
56
48
  rdoc_options: []
57
-
58
- require_paths:
49
+ require_paths:
59
50
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
51
+ required_ruby_version: !ruby/object:Gem::Requirement
61
52
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
58
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
78
63
  requirements: []
79
-
80
64
  rubyforge_project:
81
- rubygems_version: 1.8.10
65
+ rubygems_version: 1.8.22
82
66
  signing_key:
83
67
  specification_version: 3
84
68
  summary: Ruby Proxy for two or more ruby processes.
85
- test_files:
69
+ test_files:
86
70
  - unittests/test_drb_proxy.rb
87
71
  - unittests/test_config.rb
88
- - unittests/test_gloabal_var.rb
89
72
  - unittests/all_tests.rb
90
73
  - unittests/support/config.yml
91
74
  - unittests/support/image/search.png
92
75
  - unittests/support/image/start.png
93
76
  - unittests/support/atu/hello.rb
94
- - unittests/test_atu_require.rb
77
+ - unittests/test_global_var.rb
78
+ - unittests/test_require.rb
95
79
  - unittests/setup.rb