orb 0.0.5 → 0.0.6

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.
Files changed (3) hide show
  1. data/lib/orb.rb +27 -9
  2. data/orb.gemspec +1 -1
  3. metadata +2 -2
data/lib/orb.rb CHANGED
@@ -27,13 +27,11 @@ require 'orb/adapters/rspec'
27
27
 
28
28
  class ORB
29
29
  @@index=0
30
- def initialize(bind)
31
- @@index += 1
32
- @buf, @hist = [], []
33
- @line, @file = bind.eval("[__LINE__, __FILE__]")
34
-
35
- puts "\n\n[[ #{ORB::Adapter.header(bind)} ]]"
36
-
30
+
31
+ # Once ORB is called, the user is presented with a minimal IRB-like REPL,
32
+ # where they can evaluate arbitrary ruby code or execute a set of built-in
33
+ # commands to build up a test and save it back to the test file.
34
+ def orb_it_up
37
35
  while line = Readline.readline(prompt, true)
38
36
  case line
39
37
 
@@ -79,8 +77,8 @@ class ORB
79
77
  else
80
78
  @hist << [line,false]
81
79
  begin
82
- this = bind.eval("self")
83
- ret = this.send(:eval, line, this.send(:binding))
80
+ this = @binding.eval("self")
81
+ ret = this.send(:eval, line, @binding)
84
82
  rescue => e
85
83
  puts e.message
86
84
  else
@@ -89,6 +87,26 @@ class ORB
89
87
  end
90
88
 
91
89
  end
90
+ end
91
+
92
+ # It's up to the adapters to figure out the context we need to evaluate code
93
+ # in. Typically, they'll grab it from an empty block. Adapters call this
94
+ # intializer with a `Binding`, and we set a few instance variables for the
95
+ # REPL to use. Notably, `@line` and `@file` are the location of the call
96
+ # to ORB, where we should insert our code when the test is written out.
97
+ def initialize(bind)
98
+ @@index += 1
99
+ @binding = bind
100
+ @buf, @hist = [], []
101
+ @line, @file = bind.eval("[__LINE__, __FILE__]")
102
+
103
+ # This is normally used for the test's description. It's not a strict
104
+ # requirement of an adapter, but will be set and shown if present.
105
+ @header = ORB::Adapter.header(bind) if ORB::Adapter.respond_to?(:header)
106
+ puts "\n\n[[ #{@header} ]]" if @header
107
+
108
+ # Gentlemen, start your REPLs.
109
+ orb_it_up
92
110
  end
93
111
 
94
112
  private
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'orb'
3
- gem.version = "0.0.5"
3
+ gem.version = "0.0.6"
4
4
 
5
5
  gem.author, gem.email = 'Burke Libbey', "burke@burkelibbey.org"
6
6
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 5
9
- version: 0.0.5
8
+ - 6
9
+ version: 0.0.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Burke Libbey