orb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/LICENSE +19 -0
  2. data/README.md +1 -0
  3. data/lib/orb.rb +68 -0
  4. data/lib/orb/binding.rb +32 -0
  5. data/orb.gemspec +20 -0
  6. metadata +66 -0
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Burke Libbey <burke@burkelibbey.org>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1 @@
1
+ TODO: This.
@@ -0,0 +1,68 @@
1
+ require 'readline'
2
+
3
+ # TODO: load rspec or something.
4
+
5
+ module Spec
6
+ module Example
7
+ module Pending
8
+ # alias __orb_original_pending pending
9
+ def pending(message = "TODO")
10
+ Binding.of_caller do |b|
11
+ buf, line, last = [], "", ""
12
+
13
+ while line = Readline.readline("ORB >> ", true)
14
+
15
+ case line
16
+ when "a"
17
+ buf << last
18
+ next
19
+ when "p"
20
+ puts buf
21
+ next
22
+ when "q"
23
+ __orb_original_pending(message)
24
+ break
25
+ when "s"
26
+ line, file = bind.eval("[__LINE__, __FILE__]")
27
+ ORB.write_buf_to_file(buf, line, file)
28
+ break
29
+ else
30
+ begin
31
+ ctx = bind.eval("self")
32
+ ret = ctx.send(:eval, line, ctx.send(:binding))
33
+ rescue => e
34
+ puts e.message
35
+ else
36
+ puts ret.inspect
37
+ end
38
+ end
39
+
40
+ last = line
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ module ORB
49
+
50
+ def self.write_buf_to_file(buf, line_num, file)
51
+ lines = File.read(file).lines.to_a
52
+
53
+ File.open(file,"w") do |f|
54
+ f.puts lines[0...line_num-1]
55
+
56
+ orbline = lines[line_num-1]
57
+ indentation = orbline.index(/[^\s]/)
58
+
59
+ buf.each do |bufline|
60
+ f.print " "*indentation
61
+ f.puts bufline
62
+ end
63
+
64
+ f.puts lines[line_num..-1]
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,32 @@
1
+ def Binding.of_caller(&block)
2
+ old_critical, Thread.critical = Thread.critical, true
3
+ count = 0
4
+ cc = nil
5
+ result, error = callcc{|c|cc=c}
6
+ error.call if error
7
+
8
+ tracer = lambda do |*args|
9
+ type, _, _, _, context = args
10
+ if ["return", "c-return"].include?(type)
11
+ count += 1
12
+ # First this method and then calling one will return -- the trace event of the second event gets the context
13
+ # of the method which called the method that called method.
14
+ if count == 2
15
+ set_trace_func(nil)
16
+ cc.call(eval("binding", context), nil)
17
+ end
18
+ elsif type != "line"
19
+ set_trace_func(nil)
20
+ cc.call(nil, lambda { raise(Exception, "Binding.of_caller used in non-method context or trailing statements of method using it aren't in the block." ) })
21
+ end
22
+ end
23
+
24
+ if result
25
+ Thread.critical = old_critical
26
+ yield result
27
+ else
28
+ set_trace_func(tracer)
29
+ return nil
30
+ end
31
+ end
32
+
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = 'orb'
3
+ gem.version = "0.0.1"
4
+
5
+ gem.author, gem.email = 'Burke Libbey', "burke@burkelibbey.org"
6
+
7
+ gem.summary = "Interactive Testing"
8
+ gem.description = "Description pending. Also does not work yet. Just want to save the name on rubygems.org..."
9
+
10
+ # gem.required_ruby_version = '>= 1.8.7'
11
+
12
+ gem.has_rdoc = false
13
+
14
+ gem.files = %w[
15
+ LICENSE
16
+ README.md
17
+ lib
18
+ orb.gemspec
19
+ ] + Dir["**/*.rb"]
20
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orb
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Burke Libbey
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-30 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Description pending. Also does not work yet. Just want to save the name on rubygems.org...
22
+ email: burke@burkelibbey.org
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - LICENSE
31
+ - README.md
32
+ - orb.gemspec
33
+ - lib/orb/binding.rb
34
+ - lib/orb.rb
35
+ has_rdoc: true
36
+ homepage:
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ segments:
49
+ - 0
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.6
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Interactive Testing
65
+ test_files: []
66
+