partialruby 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +3 -3
  2. data/lib/partialruby.rb +38 -0
  3. data/spec/call_spec.rb +14 -0
  4. metadata +8 -8
data/Rakefile CHANGED
@@ -6,14 +6,14 @@ require 'rake/testtask'
6
6
 
7
7
  spec = Gem::Specification.new do |s|
8
8
  s.name = 'partialruby'
9
- s.version = '0.2.3'
9
+ s.version = '0.3.0'
10
10
  s.author = 'Dario Seminara'
11
11
  s.email = 'robertodarioseminara@gmail.com'
12
12
  s.platform = Gem::Platform::RUBY
13
13
  s.summary = 'Ruby partial interpreter written in pure-ruby '
14
14
  s.homepage = "http://github.com/tario/partialruby"
15
- s.add_dependency "ruby_parser", "~> 2.0"
16
- s.add_dependency "ruby2ruby", "~> 1.0"
15
+ s.add_dependency "ruby_parser", "~> 3"
16
+ s.add_dependency "ruby2ruby", "~> 2"
17
17
  s.has_rdoc = true
18
18
  s.extra_rdoc_files = [ 'README' ]
19
19
  s.rdoc_options << '--main' << 'README'
@@ -43,7 +43,21 @@ module PartialRuby
43
43
  end
44
44
  end
45
45
 
46
+ class Packet
47
+ def initialize(emulationcode) #:nodoc:
48
+ @emulationcode = emulationcode
49
+ end
50
+ def run(binding_, name = "(eval)", line = 1)
51
+ eval(@emulationcode, binding_, name, line)
52
+ end
53
+ end
54
+
46
55
  class Context
56
+
57
+ def initialize
58
+ @preprocessors = Array.new
59
+ end
60
+
47
61
  def object_ref(obj)
48
62
  "ObjectSpace._id2ref(#{obj.object_id})"
49
63
  end
@@ -66,6 +80,30 @@ module PartialRuby
66
80
  end
67
81
  end
68
82
 
83
+ def pre_process(&blk)
84
+ @preprocessors << blk
85
+ end
86
+
87
+ def packet(code)
88
+ tree = nil
89
+
90
+ begin
91
+ tree = RubyParser.new.parse code
92
+ rescue
93
+ raise SyntaxError
94
+ end
95
+
96
+ context = PartialRuby::PureRubyContext.new
97
+
98
+ @preprocessors.each do |preprocessor|
99
+ tree = preprocessor.call(tree)
100
+ end
101
+
102
+ emulationcode = context.emul tree
103
+
104
+ PartialRuby::Packet.new(emulationcode)
105
+ end
106
+
69
107
  def run(tree, frame)
70
108
  return nil unless tree
71
109
 
@@ -6,6 +6,9 @@ describe Context, "PartialRuby context" do
6
6
  class X
7
7
  def self.foo(*args)
8
8
  end
9
+
10
+ def self.bar
11
+ end
9
12
  end
10
13
 
11
14
  it "should make call without arguments" do
@@ -23,4 +26,15 @@ describe Context, "PartialRuby context" do
23
26
  end
24
27
 
25
28
  test_args "1,2,3", [1,2,3]
29
+
30
+ it "should allow breaking lines after point" do
31
+
32
+ X.should_receive(:foo).and_return(X)
33
+ to_run = <<-END
34
+ # Following 3 lines should do the same thing twice
35
+ X.foo()
36
+ .bar()
37
+ END
38
+ PartialRuby.eval(to_run, binding)
39
+ end
26
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: partialruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,30 +9,30 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-09-05 00:00:00.000000000 Z
12
+ date: 2013-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby_parser
16
- requirement: &78729160 !ruby/object:Gem::Requirement
16
+ requirement: &73591310 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '2.0'
21
+ version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *78729160
24
+ version_requirements: *73591310
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby2ruby
27
- requirement: &78728820 !ruby/object:Gem::Requirement
27
+ requirement: &73590810 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: '1.0'
32
+ version: '2'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *78728820
35
+ version_requirements: *73590810
36
36
  description:
37
37
  email: robertodarioseminara@gmail.com
38
38
  executables: []