instant 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gem "ruby_parser", "~> 2.3.1"
5
5
 
6
6
  group :development do
7
7
  gem "rspec", "~> 2.9.0"
8
- gem "rake", "~> 1.1"
8
+ gem "rake"
9
9
  gem "echoe"
10
10
  gem "autotest"
11
11
  gem "pry"
data/README.md CHANGED
@@ -4,15 +4,6 @@ An experiment on real time visualize development tool, inspired by
4
4
  [Bret Victor's Inventing on Principle](http://vimeo.com/36579366)
5
5
  talk and [@ermau C# Implementation](https://github.com/ermau/Instant).
6
6
 
7
- ## Install as gem
8
-
9
- gem install instant
10
-
11
- require 'instant'
12
-
13
- runner = Instant::Runner.new
14
- runner.run "def hello(a); a = 10 + a; end; hello(20)"
15
-
16
7
  ## Run a demo
17
8
 
18
9
  ![](http://f.cl.ly/items/0m2o252A3n1C032R2s0X/%E8%9E%A2%E5%B9%95%E5%BF%AB%E7%85%A7%202012-04-19%20%E4%B8%8A%E5%8D%8812.23.58.png)
@@ -21,11 +12,29 @@ You can run it live at [instant-ruby.herokuapp.com](http://instant-ruby.herokuap
21
12
 
22
13
  ## Run locally
23
14
 
15
+ First clone the source code from [github.com/siuying/instant](https://github.com/siuying/instant).
16
+
17
+ In the app folder, run following commands:
18
+
24
19
  bundle install
25
20
  foreman start
26
21
 
27
22
  then open your browser at http://127.0.0.1:5000/
28
23
 
24
+ ## Install as gem
25
+
26
+ Install the Gem:
27
+
28
+ gem install instant
29
+
30
+ Then in your program:
31
+
32
+ require 'rubygems'
33
+ require 'instant'
34
+
35
+ runner = Instant::Runner.new
36
+ runner.run "def hello(a); a = 10 + a; end; hello(20)"
37
+
29
38
  ## Credits
30
39
 
31
40
  - [Bret Victor's Inventing on Principle](http://vimeo.com/36579366) - this talk is just eyes opening!
data/instant.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "instant"
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Francis Chong"]
9
- s.date = "2012-04-19"
9
+ s.date = "2012-04-22"
10
10
  s.description = "An experiment on real time visualize development tool."
11
11
  s.email = "francis@ignition.hk"
12
12
  s.extra_rdoc_files = ["README.md", "lib/instant.rb", "lib/instant/context.rb", "lib/instant/processor.rb", "lib/instant/runner.rb", "lib/instant/version.rb"]
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'timeout'
2
3
 
3
4
  module Instant
4
5
  class Runner
@@ -6,13 +7,16 @@ module Instant
6
7
  @processor = processor
7
8
  end
8
9
 
9
- def run(source)
10
+ def run(source, timeout=1)
10
11
  begin
11
12
  @processed = @processor.process(source)
12
13
  context = Context.new
13
-
14
- begin
15
- return_value = context.instance_eval(@processed)
14
+ return_value = nil
15
+
16
+ begin
17
+ Timeout::timeout(timeout) do
18
+ return_value = context.instance_eval(@processed)
19
+ end
16
20
  ensure
17
21
  context.close
18
22
  end
@@ -23,6 +27,8 @@ module Instant
23
27
  {:status => :error, :cause => :parse_error, :message => format_error(e), :result => context.to_s }
24
28
  rescue Instant::LoopTooDeepError => e
25
29
  {:status => :error, :cause => :loop_too_deep, :message => "Loop too deep", :result => context.to_s }
30
+ rescue Timeout::Error => e
31
+ {:status => :error, :cause => :timeout, :message => "Timeout: code take more than #{timeout}s to run.", :result => context.to_s }
26
32
  rescue StandardError => e
27
33
  {:status => :error, :cause => :unknown, :message => format_error(e), :result => context.to_s }
28
34
  end
@@ -1,3 +1,3 @@
1
1
  module Instant
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -57,7 +57,6 @@ describe Instant::Runner do
57
57
  result = runner.run(source)
58
58
  result[:status].should == :ok
59
59
  results = result[:result].split("\n")
60
- puts results
61
60
 
62
61
  results.length.should == 4
63
62
 
@@ -65,6 +64,21 @@ describe Instant::Runner do
65
64
  results[1].strip.should =~ /i = 2/
66
65
  results[2].strip.should =~ /k = 0 | -1 | -2 | -3 | -4/
67
66
  results[3].strip.should =~ /i = 0 | 1 | 2 | 3 | 4/
68
- end
67
+ end
68
+
69
+ it "should guard against slow code" do
70
+ source = "def hello
71
+ k = 1
72
+ sleep(10)
73
+ end; hello"
74
+
75
+ runner = Instant::Runner.new
76
+ result = runner.run(source)
77
+ result[:status].should == :error
78
+ result[:cause].should == :timeout
79
+
80
+ results = result[:result].split("\n")
81
+ results[0].strip.should =~ /k = 1/
82
+ end
69
83
  end
70
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: instant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-19 00:00:00.000000000 Z
12
+ date: 2012-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby2ruby
16
- requirement: &70096086954740 !ruby/object:Gem::Requirement
16
+ requirement: &70272864264440 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.3.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70096086954740
24
+ version_requirements: *70272864264440
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: ruby_parser
27
- requirement: &70096086954240 !ruby/object:Gem::Requirement
27
+ requirement: &70272864263620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.3.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70096086954240
35
+ version_requirements: *70272864263620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70096086953720 !ruby/object:Gem::Requirement
38
+ requirement: &70272864263040 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.9.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70096086953720
46
+ version_requirements: *70272864263040
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70096086953200 !ruby/object:Gem::Requirement
49
+ requirement: &70272864262320 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '1.1'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70096086953200
57
+ version_requirements: *70272864262320
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: echoe
60
- requirement: &70096086952740 !ruby/object:Gem::Requirement
60
+ requirement: &70272864261780 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70096086952740
68
+ version_requirements: *70272864261780
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: autotest
71
- requirement: &70096086952280 !ruby/object:Gem::Requirement
71
+ requirement: &70272864260820 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70096086952280
79
+ version_requirements: *70272864260820
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: pry
82
- requirement: &70096086951760 !ruby/object:Gem::Requirement
82
+ requirement: &70272864259600 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70096086951760
90
+ version_requirements: *70272864259600
91
91
  description: An experiment on real time visualize development tool.
92
92
  email: francis@ignition.hk
93
93
  executables: []