ruby_process 0.0.4 → 0.0.5

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -16,6 +16,13 @@ class Ruby_process
16
16
  #Methods for handeling arguments and proxy-objects in arguments.
17
17
  require "#{File.dirname(__FILE__)}/../include/args_handeling.rb"
18
18
 
19
+ #Autoloader for subclasses.
20
+ def self.const_missing(name)
21
+ require "#{File.realpath(File.dirname(__FILE__))}/ruby_process_#{name.to_s.downcase}.rb"
22
+ raise "Still not defined: '#{name}'." if !self.const_defined?(name)
23
+ return self.const_get(name)
24
+ end
25
+
19
26
  #Constructor.
20
27
  #===Examples
21
28
  # Ruby_process.new.spawn_process do |rp|
@@ -0,0 +1,94 @@
1
+ require "monitor"
2
+
3
+ #This class is used to seamlessly use leaky classes without working through 'Ruby_process'.
4
+ #===Examples
5
+ # Ruby_process::Cproxy.run do |data|
6
+ # data[:subproc].static(:Object, :require, "rubygems")
7
+ # data[:subproc].static(:Object, :require, "rexml/document")
8
+ #
9
+ # doc = Ruby_process::Cproxy::REXML::Document.new("test")
10
+ # strio = StringIO.new
11
+ # doc.write(strio)
12
+ # puts strio.string #=> "<test/>"
13
+ # raise "REXML shouldnt be defined?" if Kernel.const_defined?(:REXML)
14
+ class Ruby_process::Cproxy
15
+ #Lock is used to to create new Ruby-process-instances and not doing double-counts.
16
+ @@lock = Monitor.new
17
+
18
+ #Counts how many instances are using the Cproxy-module. This way it can be safely unset once no-body is using it again.
19
+ @@instances = 0
20
+
21
+ #This variable will hold the 'Ruby_process'-object where sub-objects will be created.
22
+ @@subproc = nil
23
+
24
+ #All use should go through this method to automatically destroy sub-processes and keep track of ressources.
25
+ def self.run
26
+ #Increase count of instances that are using Cproxy and set the subproc-object if not already set.
27
+ @@lock.synchronize do
28
+ @@instances += 1
29
+
30
+ if !@@subproc
31
+ @@subproc = Ruby_process.new
32
+ @@subproc.spawn_process
33
+ end
34
+ end
35
+
36
+ begin
37
+ yield(:subproc => @@subproc)
38
+ ensure
39
+ @@lock.synchronize do
40
+ @@instances -= 1
41
+
42
+ if @@instances <= 0
43
+ @@subproc.destroy
44
+ @@subproc = nil
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ #Returns the 'Ruby_process'-object or raises an error if it has not been set.
51
+ def self.subproc
52
+ raise "CProxy process not set for some reason?" if !@@subproc
53
+ return @@subproc
54
+ end
55
+
56
+ #Creates the new constant under the 'Ruby_process::Cproxy'-namespace.
57
+ def self.const_missing(name)
58
+ Ruby_process::Cproxy.load_class(self, name) if !self.const_defined?(name)
59
+ raise "Still not created on const: '#{name}'." if !self.const_defined?(name)
60
+ return self.const_get(name)
61
+ end
62
+
63
+ #Loads a new class to the given constants namespace for recursive creating of missing classes.
64
+ def self.load_class(const, name)
65
+ const.const_set(name, Class.new{
66
+ #Use 'const_missing' to auto-create missing sub-constants recursivly.
67
+ def self.const_missing(name)
68
+ Ruby_process::Cproxy.load_class(self, name) if !self.const_defined?(name)
69
+ raise "Still not created on const: '#{name}'." if !self.const_defined?(name)
70
+ return self.const_get(name)
71
+ end
72
+
73
+ #Manipulate 'new'-method return proxy-objects instead of real objects.
74
+ def self.new(*args, &blk)
75
+ name_match = self.name.to_s.match(/^Ruby_process::Cproxy::(.+)$/)
76
+ class_name = name_match[1]
77
+
78
+ subproc = Ruby_process::Cproxy.subproc
79
+ obj = subproc.new(class_name, *args, &blk)
80
+
81
+ return obj
82
+ end
83
+
84
+ def self.method_missing(method_name, *args, &blk)
85
+ name_match = self.name.to_s.match(/^Ruby_process::Cproxy::(.+)$/)
86
+ class_name = name_match[1]
87
+
88
+ subproc = Ruby_process::Cproxy.subproc
89
+
90
+ return subproc.static(class_name, method_name, *args, &blk)
91
+ end
92
+ })
93
+ end
94
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ruby_process}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = %q{2012-10-10}
12
+ s.date = %q{2012-10-14}
13
13
  s.description = %q{A framework for spawning and communicating with other Ruby-processes}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.extra_rdoc_files = [
@@ -36,8 +36,10 @@ Gem::Specification.new do |s|
36
36
  "examples/example_strscan.rb",
37
37
  "include/args_handeling.rb",
38
38
  "lib/ruby_process.rb",
39
+ "lib/ruby_process_cproxy.rb",
39
40
  "ruby_process.gemspec",
40
41
  "scripts/ruby_process_script.rb",
42
+ "spec/cproxy_spec.rb",
41
43
  "spec/ruby_process_spec.rb",
42
44
  "spec/spec_helper.rb"
43
45
  ]
@@ -0,0 +1,21 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "RubyProcess" do
4
+ it "should be able to do basic stuff" do
5
+ require "stringio"
6
+
7
+ Ruby_process::Cproxy.run do |data|
8
+ data[:subproc].static(:Object, :require, "rubygems")
9
+ data[:subproc].static(:Object, :require, "rexml/document")
10
+
11
+ doc = Ruby_process::Cproxy::REXML::Document.new
12
+ doc.add_element("test")
13
+
14
+ strio = StringIO.new
15
+ doc.write(strio)
16
+
17
+ raise "Didnt expect REXML to be defined in host process." if Kernel.const_defined?(:REXML)
18
+ raise "Expected strio to contain '<test/>' but it didnt: '#{strio.string}'." if strio.string != "<test/>"
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_process
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 +02:00
12
+ date: 2012-10-14 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: wref
17
- requirement: &11532040 !ruby/object:Gem::Requirement
17
+ requirement: &12566380 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *11532040
25
+ version_requirements: *12566380
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: tsafe
28
- requirement: &11531160 !ruby/object:Gem::Requirement
28
+ requirement: &12565660 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *11531160
36
+ version_requirements: *12565660
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &11530360 !ruby/object:Gem::Requirement
39
+ requirement: &12564900 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.8.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *11530360
47
+ version_requirements: *12564900
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rdoc
50
- requirement: &11529480 !ruby/object:Gem::Requirement
50
+ requirement: &12564260 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '3.12'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *11529480
58
+ version_requirements: *12564260
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: bundler
61
- requirement: &11528660 !ruby/object:Gem::Requirement
61
+ requirement: &12563400 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.0.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *11528660
69
+ version_requirements: *12563400
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: jeweler
72
- requirement: &11527920 !ruby/object:Gem::Requirement
72
+ requirement: &12562600 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 1.8.3
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *11527920
80
+ version_requirements: *12562600
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: rcov
83
- requirement: &11527180 !ruby/object:Gem::Requirement
83
+ requirement: &12561560 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,7 +88,7 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *11527180
91
+ version_requirements: *12561560
92
92
  description: A framework for spawning and communicating with other Ruby-processes
93
93
  email: k@spernj.org
94
94
  executables: []
@@ -116,8 +116,10 @@ files:
116
116
  - examples/example_strscan.rb
117
117
  - include/args_handeling.rb
118
118
  - lib/ruby_process.rb
119
+ - lib/ruby_process_cproxy.rb
119
120
  - ruby_process.gemspec
120
121
  - scripts/ruby_process_script.rb
122
+ - spec/cproxy_spec.rb
121
123
  - spec/ruby_process_spec.rb
122
124
  - spec/spec_helper.rb
123
125
  has_rdoc: true
@@ -136,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
138
  version: '0'
137
139
  segments:
138
140
  - 0
139
- hash: -762115718297605832
141
+ hash: 4244816793884101144
140
142
  required_rubygems_version: !ruby/object:Gem::Requirement
141
143
  none: false
142
144
  requirements: