rib 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -5
- data/CHANGES.md +16 -0
- data/README.md +63 -13
- data/Rakefile +6 -4
- data/lib/rib/api.rb +14 -6
- data/lib/rib/app/auto.rb +1 -1
- data/lib/rib/core.rb +1 -1
- data/lib/rib/core/last_value.rb +35 -0
- data/lib/rib/core/strip_backtrace.rb +6 -5
- data/lib/rib/extra/paging.rb +10 -14
- data/lib/rib/more.rb +1 -0
- data/lib/rib/more/anchor.rb +0 -18
- data/lib/rib/more/bottomup_backtrace.rb +5 -1
- data/lib/rib/more/caller.rb +37 -0
- data/lib/rib/more/color.rb +5 -1
- data/lib/rib/runner.rb +5 -6
- data/lib/rib/test.rb +4 -3
- data/lib/rib/test/multiline.rb +11 -3
- data/lib/rib/version.rb +1 -1
- data/rib.gemspec +12 -10
- data/task/README.md +4 -4
- data/task/gemgem.rb +23 -6
- data/test/core/test_last_value.rb +36 -0
- data/test/core/test_multiline.rb +0 -9
- data/test/extra/test_anchor.rb +18 -0
- data/test/more/test_caller.rb +15 -0
- metadata +10 -8
- data/bin/rib-ramaze +0 -12
- data/lib/rib/app/ramaze.rb +0 -29
- data/lib/rib/core/underscore.rb +0 -56
- data/test/core/test_underscore.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2754a503227af3de8a1ce5be17d51953c5660c66
|
4
|
+
data.tar.gz: 82d087ef01b20d8ff6c23300a734cdf48c97d144
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2013ad9a9dfe0e067d4c753364cc64650e92cf0e4a423c0451016e109ddadd6c1837fc863df6c83abfb9a30d1d27fe25ae536dbabca9507901845cff6ecae5a6
|
7
|
+
data.tar.gz: c46d5ac3913b05d761c67b8138ec5f970dad67af9b14a6e36b5d9bf01419e805b603df1cec73dd4a184d18ccaf9960b0d6d632a70d2380291450d22828fd01bd
|
data/.travis.yml
CHANGED
@@ -1,10 +1,5 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
|
-
rvm:
|
4
|
-
- 2.2.5
|
5
|
-
- 2.3.1
|
6
|
-
- rbx
|
7
|
-
- jruby-9
|
8
3
|
|
9
4
|
before_install:
|
10
5
|
- rvm get head
|
@@ -14,5 +9,13 @@ install: 'gem install bundler; bundle install --retry=3'
|
|
14
9
|
script: 'ruby -r bundler/setup -S rake test'
|
15
10
|
|
16
11
|
matrix:
|
12
|
+
include:
|
13
|
+
- rvm: 2.2.5
|
14
|
+
- rvm: 2.3.2
|
15
|
+
- rvm: 2.4.0
|
16
|
+
- rvm: jruby-9
|
17
|
+
env: JRUBY_OPTS=--debug
|
18
|
+
- rvm: rbx
|
19
|
+
|
17
20
|
allow_failures:
|
18
21
|
- rvm: rbx
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,21 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Rib 1.5.0 -- 2016-02-27
|
4
|
+
|
5
|
+
* Removed Ramaze direct support. Use Rack instead.
|
6
|
+
* Introduced API#format_backtrace
|
7
|
+
* Introduced API#puts
|
8
|
+
* [more/anchor] Fixed multiline support when anchoring on an object
|
9
|
+
* [more/caller] Added for showing formatted call stack
|
10
|
+
* [core/underscore] This is changed to `core/last_value`, and the API is
|
11
|
+
changed to `Rib.last_value` and `Rib.last_exception`. Surely this is less
|
12
|
+
intrusive and more compatible for things like `Rib.anchor 42` because
|
13
|
+
now literal integers are frozen and we cannot define methods on them.
|
14
|
+
Also, using `Rib.last_value` is surely more descriptive. Of course,
|
15
|
+
being able to type `_` is so much easier, but you could just add a plugin
|
16
|
+
which defines `def _; Rib.last_value; end` and keep using `_` for your
|
17
|
+
own taste!
|
18
|
+
|
3
19
|
## Rib 1.4.0 -- 2016-11-11
|
4
20
|
|
5
21
|
* Search Rib home by directories rather than config/history file.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Rib [![Build Status](https://secure.travis-ci.org/godfat/rib.png?branch=master)](http://travis-ci.org/godfat/rib) [![Coverage Status](https://coveralls.io/repos/godfat/rib/badge.png)](https://coveralls.io/
|
1
|
+
# Rib [![Build Status](https://secure.travis-ci.org/godfat/rib.png?branch=master)](http://travis-ci.org/godfat/rib) [![Coverage Status](https://coveralls.io/repos/github/godfat/rib/badge.png)](https://coveralls.io/github/godfat/rib) [![Join the chat at https://gitter.im/godfat/rib](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/godfat/rib)
|
2
2
|
|
3
3
|
by Lin Jen-Shin ([godfat](http://godfat.org))
|
4
4
|
|
@@ -61,16 +61,12 @@ in your `~/.spring.rb`:
|
|
61
61
|
|
62
62
|
require 'rib/extra/spring'
|
63
63
|
|
64
|
-
As Ramaze console
|
65
|
-
|
66
|
-
rib ramaze
|
67
|
-
|
68
64
|
As Rack console
|
69
65
|
|
70
66
|
rib rack
|
71
67
|
|
72
68
|
As a console for whichever the app in the current path
|
73
|
-
it should be (for now, it's either Rails
|
69
|
+
it should be (for now, it's either Rails or Rack)
|
74
70
|
|
75
71
|
rib auto
|
76
72
|
|
@@ -195,11 +191,10 @@ rib options:
|
|
195
191
|
-v, --version Print the version
|
196
192
|
rib commands:
|
197
193
|
min Run the minimum essence
|
198
|
-
auto Run as Rails or
|
194
|
+
auto Run as Rails or Rack console (auto-detect)
|
199
195
|
all Load all recommended plugins
|
200
196
|
rails Run as Rails console
|
201
197
|
rack Run as Rack console
|
202
|
-
ramaze Run as Ramaze console
|
203
198
|
```
|
204
199
|
|
205
200
|
#### Basic configuration
|
@@ -253,9 +248,10 @@ require 'rib/core' # You get all of the followings:
|
|
253
248
|
|
254
249
|
Remove duplicated input from history.
|
255
250
|
|
256
|
-
* `require 'rib/core/
|
251
|
+
* `require 'rib/core/last_value'`
|
257
252
|
|
258
|
-
Save the last result in `
|
253
|
+
Save the last result in `Rib.last_value` and the last exception in
|
254
|
+
`Rib.last_exception`.
|
259
255
|
|
260
256
|
#### List of more plugins
|
261
257
|
|
@@ -283,6 +279,10 @@ require 'rib/more' # You get all of the followings:
|
|
283
279
|
|
284
280
|
See _As a debugging/interacting tool_.
|
285
281
|
|
282
|
+
* `require 'rib/more/caller'`
|
283
|
+
|
284
|
+
See _Current call stack (backtrace, caller)_.
|
285
|
+
|
286
286
|
* `require 'rib/more/edit'`
|
287
287
|
|
288
288
|
See _In place editing_.
|
@@ -347,6 +347,7 @@ enter the shell under certain circumstance, then you'll do:
|
|
347
347
|
|
348
348
|
``` ruby
|
349
349
|
require 'rib/debug'
|
350
|
+
|
350
351
|
Rib.enable_anchor do
|
351
352
|
# Only `Rib.anchor` called in the block would launch a shell
|
352
353
|
end
|
@@ -357,12 +358,61 @@ Rib.anchor binding # No effect (no-op) outside the block
|
|
357
358
|
Anchor could also be nested. The level would be shown on the prompt,
|
358
359
|
starting from 1.
|
359
360
|
|
361
|
+
### Current call stack (backtrace, caller)
|
362
|
+
|
363
|
+
Often time we would want to see current call stack whenever we're using
|
364
|
+
`Rib.anchor`. We could do that by simply using `caller` but it's barely
|
365
|
+
readable because it's just returning an array without any format and
|
366
|
+
it also contains backtrace from Rib itself. You could use pretty
|
367
|
+
formatting with Rib:
|
368
|
+
|
369
|
+
``` ruby
|
370
|
+
require 'rib/more/caller'
|
371
|
+
|
372
|
+
Rib.caller
|
373
|
+
```
|
374
|
+
|
375
|
+
It would use the same format for exception backtrace to show current
|
376
|
+
call stack for you. Colors, bottom up order, etc, if you're also using
|
377
|
+
the corresponding plugins.
|
378
|
+
|
379
|
+
Sometimes there are also too many stack frames which we don't care about.
|
380
|
+
In this case, we could pass arguments to `Rib.caller` in order to filter
|
381
|
+
against them. You could either pass:
|
382
|
+
|
383
|
+
* A `String` represents the name of the gem you don't care
|
384
|
+
* A `Regexp` which would be used to match against paths/methods you don't care
|
385
|
+
|
386
|
+
Examples:
|
387
|
+
|
388
|
+
``` ruby
|
389
|
+
require 'rib/more/caller'
|
390
|
+
|
391
|
+
Rib.caller 'activesupport', /rspec/
|
392
|
+
```
|
393
|
+
|
394
|
+
To remove backtrace from gem _activesupport_ and paths or methods containing
|
395
|
+
rspec as part of the name, like things for _rspec_ or _rspec-core_ and so on.
|
396
|
+
Note that if a method name also contains rspec then it would also be filtered.
|
397
|
+
Just keep that in mind when using regular expression.
|
398
|
+
|
399
|
+
Or if you don't care about any gems, only want to see application related
|
400
|
+
calls, then try to match against `%r{/gems/}` because gems are often stored
|
401
|
+
in a path containing `/gems/`:
|
402
|
+
|
403
|
+
```
|
404
|
+
Rib.caller %r{/gem/}
|
405
|
+
```
|
406
|
+
|
407
|
+
Happy debugging.
|
408
|
+
|
360
409
|
### In place editing
|
361
410
|
|
362
411
|
Whenever you called:
|
363
412
|
|
364
413
|
``` ruby
|
365
414
|
require 'rib/more/edit'
|
415
|
+
|
366
416
|
Rib.edit
|
367
417
|
```
|
368
418
|
|
@@ -380,8 +430,8 @@ require 'rib'
|
|
380
430
|
```
|
381
431
|
|
382
432
|
All others are optional. The core plugins are lying in `rib/core/*.rb`, and
|
383
|
-
more plugins are lying in `rib/more/*.rb`. You can read `rib/app/
|
384
|
-
and `bin/rib-
|
433
|
+
more plugins are lying in `rib/more/*.rb`. You can read `rib/app/rack.rb`
|
434
|
+
and `bin/rib-rack` as a Rib App reference implementation, because it's very
|
385
435
|
simple, simpler than rib-rails.
|
386
436
|
|
387
437
|
## Other plugins and apps
|
@@ -405,7 +455,7 @@ simple, simpler than rib-rails.
|
|
405
455
|
|
406
456
|
Apache License 2.0
|
407
457
|
|
408
|
-
Copyright (c) 2011-
|
458
|
+
Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
|
409
459
|
|
410
460
|
Licensed under the Apache License, Version 2.0 (the "License");
|
411
461
|
you may not use this file except in compliance with the License.
|
data/Rakefile
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
|
2
2
|
begin
|
3
|
-
require "#{
|
3
|
+
require "#{__dir__}/task/gemgem"
|
4
4
|
rescue LoadError
|
5
|
-
sh 'git submodule update --init'
|
5
|
+
sh 'git submodule update --init --recursive'
|
6
6
|
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
7
7
|
end
|
8
8
|
|
9
|
-
Gemgem.init(
|
9
|
+
Gemgem.init(__dir__) do |s|
|
10
10
|
require 'rib/version'
|
11
11
|
s.name = 'rib'
|
12
12
|
s.version = Rib::VERSION
|
13
|
-
|
13
|
+
%w[screenshot.png asciicast.json].each do |file|
|
14
|
+
s.files.delete(file)
|
15
|
+
end
|
14
16
|
end
|
data/lib/rib/api.rb
CHANGED
@@ -23,10 +23,6 @@ module Rib::API
|
|
23
23
|
def eval_binding ; config[:binding] ; end
|
24
24
|
# The line number for next evaluation
|
25
25
|
def line ; config[:line] ; end
|
26
|
-
# The object for the current binding
|
27
|
-
def bound_object
|
28
|
-
config[:bound_object] ||= eval_binding.eval('self', __FILE__, __LINE__)
|
29
|
-
end
|
30
26
|
|
31
27
|
# Main loop
|
32
28
|
def in_loop
|
@@ -74,7 +70,11 @@ module Rib::API
|
|
74
70
|
|
75
71
|
# Evaluate user input with #eval_binding, name and line
|
76
72
|
def loop_eval input
|
77
|
-
eval_binding.
|
73
|
+
if eval_binding.kind_of?(Binding)
|
74
|
+
eval_binding.eval(input, "(#{name})", line)
|
75
|
+
else
|
76
|
+
eval_binding.instance_eval(input, "(#{name})", line)
|
77
|
+
end
|
78
78
|
end
|
79
79
|
|
80
80
|
# Print result using #format_result
|
@@ -91,6 +91,10 @@ module Rib::API
|
|
91
91
|
Rib.warn("Error while printing error:\n #{format_error(e)}")
|
92
92
|
end
|
93
93
|
|
94
|
+
def puts str
|
95
|
+
super
|
96
|
+
end
|
97
|
+
|
94
98
|
# Format result using #result_prompt
|
95
99
|
def format_result result
|
96
100
|
result_prompt + result.inspect
|
@@ -105,10 +109,14 @@ module Rib::API
|
|
105
109
|
|
106
110
|
# Get error message and backtrace from a particular error
|
107
111
|
def get_error err
|
108
|
-
["#{err.class}: #{err.message}", err.backtrace]
|
112
|
+
["#{err.class}: #{err.message}", format_backtrace(err.backtrace)]
|
109
113
|
end
|
110
114
|
module_function :get_error
|
111
115
|
|
116
|
+
def format_backtrace backtrace
|
117
|
+
backtrace
|
118
|
+
end
|
119
|
+
|
112
120
|
private
|
113
121
|
def equal_rib_skip result
|
114
122
|
result == Rib::Skip
|
data/lib/rib/app/auto.rb
CHANGED
data/lib/rib/core.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
require 'rib'
|
3
|
+
|
4
|
+
module Rib::LastValue
|
5
|
+
extend Rib::Plugin
|
6
|
+
Shell.use(self)
|
7
|
+
|
8
|
+
attr_reader :last_value, :last_exception
|
9
|
+
|
10
|
+
def print_result result
|
11
|
+
return super if LastValue.disabled?
|
12
|
+
@last_value = result
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def print_eval_error err
|
17
|
+
return super if LastValue.disabled?
|
18
|
+
@last_exception = err
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
module Imp
|
25
|
+
def last_value
|
26
|
+
Rib.shell.last_value
|
27
|
+
end
|
28
|
+
|
29
|
+
def last_exception
|
30
|
+
Rib.shell.last_exception
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Rib.extend(Imp)
|
35
|
+
end
|
@@ -15,14 +15,15 @@ module Rib::StripBacktrace
|
|
15
15
|
|
16
16
|
def get_error err
|
17
17
|
return super if StripBacktrace.disabled?
|
18
|
-
["#{err.class}: #{err.message}",
|
18
|
+
["#{err.class}: #{err.message}", format_backtrace(err.backtrace)]
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
21
|
module_function
|
24
|
-
def
|
25
|
-
|
22
|
+
def format_backtrace backtrace
|
23
|
+
return super if StripBacktrace.disabled?
|
24
|
+
strip_home_backtrace(
|
25
|
+
strip_cwd_backtrace(
|
26
|
+
strip_rib_backtrace(super(backtrace))))
|
26
27
|
end
|
27
28
|
|
28
29
|
def strip_home_backtrace backtrace
|
data/lib/rib/extra/paging.rb
CHANGED
@@ -7,31 +7,27 @@ module Rib::Paging
|
|
7
7
|
|
8
8
|
# --------------- Rib API ---------------
|
9
9
|
|
10
|
-
# Print
|
11
|
-
|
12
|
-
def print_result result
|
10
|
+
# Print if the it fits one screen, paging it through a pager otherwise.
|
11
|
+
def puts str=''
|
13
12
|
return super if Paging.disabled?
|
14
|
-
|
15
|
-
|
16
|
-
puts output
|
13
|
+
if one_screen?(str)
|
14
|
+
super
|
17
15
|
else
|
18
|
-
page_result(
|
16
|
+
page_result(str)
|
19
17
|
end
|
20
|
-
rescue StandardError, SyntaxError => e
|
21
|
-
Rib.warn("Error while printing result:\n #{format_error(e)}")
|
22
18
|
end
|
23
19
|
|
24
20
|
# `less -F` can't cat the output, so we need to detect by ourselves.
|
25
21
|
# `less -X` would mess up the buffers, so it's not desired, either.
|
26
|
-
def one_screen?
|
22
|
+
def one_screen? str
|
27
23
|
cols, lines = `tput cols`.to_i, `tput lines`.to_i
|
28
|
-
|
29
|
-
|
24
|
+
(str.count("\n") + 2) <= lines && # count last line and prompt
|
25
|
+
str.gsub(/\e\[[^m]*m/, '').size <= cols * lines
|
30
26
|
end
|
31
27
|
|
32
|
-
def page_result
|
28
|
+
def page_result str
|
33
29
|
less = IO.popen(pager, 'w')
|
34
|
-
less.write(
|
30
|
+
less.write(str)
|
35
31
|
less.close_write
|
36
32
|
rescue Errno::EPIPE
|
37
33
|
# less quit without consuming all the input
|
data/lib/rib/more.rb
CHANGED
data/lib/rib/more/anchor.rb
CHANGED
@@ -7,15 +7,6 @@ module Rib::Anchor
|
|
7
7
|
|
8
8
|
# --------------- Rib API ---------------
|
9
9
|
|
10
|
-
def loop_eval input
|
11
|
-
return super if Rib::Anchor.disabled?
|
12
|
-
if eval_binding.kind_of?(Binding)
|
13
|
-
super
|
14
|
-
else
|
15
|
-
eval_binding.instance_eval(input, "(#{name})", line)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
10
|
def prompt
|
20
11
|
return super if Rib::Anchor.disabled?
|
21
12
|
return super unless config[:prompt_anchor]
|
@@ -31,15 +22,6 @@ module Rib::Anchor
|
|
31
22
|
end
|
32
23
|
end
|
33
24
|
|
34
|
-
# --------------- Plugin API ---------------
|
35
|
-
|
36
|
-
# override Underscore#bound_object
|
37
|
-
def bound_object
|
38
|
-
return super if Rib::Anchor.disabled?
|
39
|
-
return super if eval_binding.kind_of?(Binding)
|
40
|
-
eval_binding
|
41
|
-
end
|
42
|
-
|
43
25
|
|
44
26
|
|
45
27
|
private
|
@@ -10,6 +10,10 @@ module Rib::BottomupBacktrace
|
|
10
10
|
def format_error err
|
11
11
|
return super if BottomupBacktrace.disabled?
|
12
12
|
message, backtrace = get_error(err)
|
13
|
-
" #{backtrace.
|
13
|
+
" #{format_backtrace(backtrace).join("\n ")}\n#{message}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def format_backtrace backtrace
|
17
|
+
super(backtrace).reverse
|
14
18
|
end
|
15
19
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
require 'rib'
|
3
|
+
|
4
|
+
module Rib::Caller
|
5
|
+
extend Rib::Plugin
|
6
|
+
Shell.use(self)
|
7
|
+
|
8
|
+
module Imp
|
9
|
+
def caller *filters
|
10
|
+
return if Rib::Caller.disabled?
|
11
|
+
|
12
|
+
backtrace = Rib.shell.format_backtrace(super().drop(1))
|
13
|
+
|
14
|
+
lib = %r{\brib-#{Rib::VERSION}/lib/rib/}
|
15
|
+
if backtrace.first =~ lib
|
16
|
+
backtrace.shift while backtrace.first =~ lib
|
17
|
+
elsif backtrace.last =~ lib
|
18
|
+
backtrace.pop while backtrace.last =~ lib
|
19
|
+
end
|
20
|
+
|
21
|
+
result = filters.map do |f|
|
22
|
+
case f
|
23
|
+
when Regexp
|
24
|
+
f
|
25
|
+
when String
|
26
|
+
%r{\bgems/#{Regexp.escape(f)}\-[\d\.]+/lib/}
|
27
|
+
end
|
28
|
+
end.inject(backtrace, &:grep_v)
|
29
|
+
|
30
|
+
Rib.shell.puts result.map{ |l| " #{l}" }.join("\n")
|
31
|
+
|
32
|
+
Rib::Skip
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Rib.extend(Imp)
|
37
|
+
end
|
data/lib/rib/more/color.rb
CHANGED
@@ -20,7 +20,7 @@ module Rib::Color
|
|
20
20
|
def get_error err
|
21
21
|
return super if Color.disabled?
|
22
22
|
message, backtrace = super
|
23
|
-
[format_color(err, message),
|
23
|
+
[format_color(err, message), format_backtrace(backtrace)]
|
24
24
|
end
|
25
25
|
|
26
26
|
# --------------- Plugin API ---------------
|
@@ -71,6 +71,10 @@ module Rib::Color
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
def format_backtrace backtrace
|
75
|
+
colorize_backtrace(super(backtrace))
|
76
|
+
end
|
77
|
+
|
74
78
|
|
75
79
|
|
76
80
|
module_function
|
data/lib/rib/runner.rb
CHANGED
@@ -51,12 +51,11 @@ module Rib::Runner
|
|
51
51
|
|
52
52
|
def command_descriptions
|
53
53
|
@command_descriptions ||=
|
54
|
-
{'all' => 'Load all recommended plugins'
|
55
|
-
'min' => 'Run the minimum essence'
|
56
|
-
'auto' => 'Run as Rails or
|
57
|
-
'rails' => 'Run as Rails console'
|
58
|
-
'
|
59
|
-
'rack' => 'Run as Rack console' }
|
54
|
+
{'all' => 'Load all recommended plugins' ,
|
55
|
+
'min' => 'Run the minimum essence' ,
|
56
|
+
'auto' => 'Run as Rails or Rack console (auto-detect)',
|
57
|
+
'rails' => 'Run as Rails console' ,
|
58
|
+
'rack' => 'Run as Rack console' }
|
60
59
|
end
|
61
60
|
|
62
61
|
# Extract the text below __END__ in the bin file as the description
|
data/lib/rib/test.rb
CHANGED
@@ -7,13 +7,14 @@ Pork::Suite.include(Muack::API)
|
|
7
7
|
require 'rib'
|
8
8
|
|
9
9
|
copy :rib do
|
10
|
-
before do
|
11
|
-
end
|
12
|
-
|
13
10
|
after do
|
14
11
|
Muack.verify
|
15
12
|
end
|
16
13
|
|
14
|
+
def new_shell
|
15
|
+
Rib::Shell.new(:binding => Object.new.instance_eval{binding}).before_loop
|
16
|
+
end
|
17
|
+
|
17
18
|
singleton_class.module_eval do
|
18
19
|
def test_for *plugins, &block
|
19
20
|
require 'rib/all' # exhaustive tests
|
data/lib/rib/test/multiline.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
|
2
2
|
copy :setup_multiline do
|
3
3
|
def setup_shell
|
4
|
-
@shell =
|
5
|
-
:binding => Object.new.instance_eval{binding}).before_loop
|
4
|
+
@shell = new_shell
|
6
5
|
stub(@shell).print{}.with_any_args
|
7
6
|
stub(@shell).puts{} .with_any_args
|
8
7
|
end
|
@@ -30,7 +29,16 @@ copy :setup_multiline do
|
|
30
29
|
mock(@shell).print_result(is_a(Object)){}
|
31
30
|
end
|
32
31
|
@shell.loop_once
|
33
|
-
|
32
|
+
ok
|
33
|
+
end
|
34
|
+
|
35
|
+
def check str, err=nil
|
36
|
+
lines = str.split("\n")
|
37
|
+
lines[0...-1].each{ |line|
|
38
|
+
input(line)
|
39
|
+
@shell.loop_once
|
40
|
+
}
|
41
|
+
input_done(lines.last, err)
|
34
42
|
end
|
35
43
|
end
|
36
44
|
|
data/lib/rib/version.rb
CHANGED
data/rib.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: rib 1.
|
2
|
+
# stub: rib 1.5.0 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "rib".freeze
|
6
|
-
s.version = "1.
|
6
|
+
s.version = "1.5.0"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib".freeze]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)".freeze]
|
11
|
-
s.date = "
|
11
|
+
s.date = "2017-02-27"
|
12
12
|
s.description = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell\n\nRib is based on the design of [ripl][] and the work of [ripl-rc][], some of\nthe features are also inspired by [pry][]. The aim of Rib is to be fully\nfeatured and yet very easy to opt-out or opt-in other features. It shall\nbe simple, lightweight and modular so that everyone could customize Rib.\n\n[ripl]: https://github.com/cldwalker/ripl\n[ripl-rc]: https://github.com/godfat/ripl-rc\n[pry]: https://github.com/pry/pry".freeze
|
13
13
|
s.email = ["godfat (XD) godfat.org".freeze]
|
14
14
|
s.executables = [
|
@@ -17,8 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
"rib-auto".freeze,
|
18
18
|
"rib-min".freeze,
|
19
19
|
"rib-rack".freeze,
|
20
|
-
"rib-rails".freeze
|
21
|
-
"rib-ramaze".freeze]
|
20
|
+
"rib-rails".freeze]
|
22
21
|
s.files = [
|
23
22
|
".gitignore".freeze,
|
24
23
|
".gitmodules".freeze,
|
@@ -35,23 +34,21 @@ Gem::Specification.new do |s|
|
|
35
34
|
"bin/rib-min".freeze,
|
36
35
|
"bin/rib-rack".freeze,
|
37
36
|
"bin/rib-rails".freeze,
|
38
|
-
"bin/rib-ramaze".freeze,
|
39
37
|
"lib/rib.rb".freeze,
|
40
38
|
"lib/rib/all.rb".freeze,
|
41
39
|
"lib/rib/api.rb".freeze,
|
42
40
|
"lib/rib/app/auto.rb".freeze,
|
43
41
|
"lib/rib/app/rack.rb".freeze,
|
44
42
|
"lib/rib/app/rails.rb".freeze,
|
45
|
-
"lib/rib/app/ramaze.rb".freeze,
|
46
43
|
"lib/rib/config.rb".freeze,
|
47
44
|
"lib/rib/core.rb".freeze,
|
48
45
|
"lib/rib/core/completion.rb".freeze,
|
49
46
|
"lib/rib/core/history.rb".freeze,
|
47
|
+
"lib/rib/core/last_value.rb".freeze,
|
50
48
|
"lib/rib/core/multiline.rb".freeze,
|
51
49
|
"lib/rib/core/readline.rb".freeze,
|
52
50
|
"lib/rib/core/squeeze_history.rb".freeze,
|
53
51
|
"lib/rib/core/strip_backtrace.rb".freeze,
|
54
|
-
"lib/rib/core/underscore.rb".freeze,
|
55
52
|
"lib/rib/debug.rb".freeze,
|
56
53
|
"lib/rib/extra/autoindent.rb".freeze,
|
57
54
|
"lib/rib/extra/hirb.rb".freeze,
|
@@ -60,6 +57,7 @@ Gem::Specification.new do |s|
|
|
60
57
|
"lib/rib/more.rb".freeze,
|
61
58
|
"lib/rib/more/anchor.rb".freeze,
|
62
59
|
"lib/rib/more/bottomup_backtrace.rb".freeze,
|
60
|
+
"lib/rib/more/caller.rb".freeze,
|
63
61
|
"lib/rib/more/color.rb".freeze,
|
64
62
|
"lib/rib/more/edit.rb".freeze,
|
65
63
|
"lib/rib/more/multiline_history.rb".freeze,
|
@@ -75,12 +73,14 @@ Gem::Specification.new do |s|
|
|
75
73
|
"task/gemgem.rb".freeze,
|
76
74
|
"test/core/test_completion.rb".freeze,
|
77
75
|
"test/core/test_history.rb".freeze,
|
76
|
+
"test/core/test_last_value.rb".freeze,
|
78
77
|
"test/core/test_multiline.rb".freeze,
|
79
78
|
"test/core/test_readline.rb".freeze,
|
80
79
|
"test/core/test_squeeze_history.rb".freeze,
|
81
80
|
"test/core/test_strip_backtrace.rb".freeze,
|
82
|
-
"test/
|
81
|
+
"test/extra/test_anchor.rb".freeze,
|
83
82
|
"test/extra/test_autoindent.rb".freeze,
|
83
|
+
"test/more/test_caller.rb".freeze,
|
84
84
|
"test/more/test_color.rb".freeze,
|
85
85
|
"test/more/test_multiline_history.rb".freeze,
|
86
86
|
"test/test_api.rb".freeze,
|
@@ -94,12 +94,14 @@ Gem::Specification.new do |s|
|
|
94
94
|
s.test_files = [
|
95
95
|
"test/core/test_completion.rb".freeze,
|
96
96
|
"test/core/test_history.rb".freeze,
|
97
|
+
"test/core/test_last_value.rb".freeze,
|
97
98
|
"test/core/test_multiline.rb".freeze,
|
98
99
|
"test/core/test_readline.rb".freeze,
|
99
100
|
"test/core/test_squeeze_history.rb".freeze,
|
100
101
|
"test/core/test_strip_backtrace.rb".freeze,
|
101
|
-
"test/
|
102
|
+
"test/extra/test_anchor.rb".freeze,
|
102
103
|
"test/extra/test_autoindent.rb".freeze,
|
104
|
+
"test/more/test_caller.rb".freeze,
|
103
105
|
"test/more/test_color.rb".freeze,
|
104
106
|
"test/more/test_multiline_history.rb".freeze,
|
105
107
|
"test/test_api.rb".freeze,
|
data/task/README.md
CHANGED
@@ -13,7 +13,7 @@ Provided tasks:
|
|
13
13
|
|
14
14
|
## REQUIREMENTS:
|
15
15
|
|
16
|
-
* Tested with MRI (official CRuby)
|
16
|
+
* Tested with MRI (official CRuby), Rubinius and JRuby.
|
17
17
|
|
18
18
|
## INSTALLATION:
|
19
19
|
|
@@ -23,13 +23,13 @@ And in Rakefile:
|
|
23
23
|
|
24
24
|
``` ruby
|
25
25
|
begin
|
26
|
-
require "#{
|
26
|
+
require "#{__dir__}/task/gemgem"
|
27
27
|
rescue LoadError
|
28
28
|
sh 'git submodule update --init'
|
29
29
|
exec Gem.ruby, '-S', $PROGRAM_NAME, *ARGV
|
30
30
|
end
|
31
31
|
|
32
|
-
Gemgem.init(
|
32
|
+
Gemgem.init(__dir__, :submodules => %w[your-dep]) do |s|
|
33
33
|
s.name = 'your-gem'
|
34
34
|
s.version = '0.1.0'
|
35
35
|
end
|
@@ -39,7 +39,7 @@ end
|
|
39
39
|
|
40
40
|
Apache License 2.0
|
41
41
|
|
42
|
-
Copyright (c) 2011-
|
42
|
+
Copyright (c) 2011-2016, Lin Jen-Shin (godfat)
|
43
43
|
|
44
44
|
Licensed under the Apache License, Version 2.0 (the "License");
|
45
45
|
you may not use this file except in compliance with the License.
|
data/task/gemgem.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
module Gemgem
|
3
3
|
class << self
|
4
|
-
attr_accessor :dir, :spec, :spec_create
|
4
|
+
attr_accessor :dir, :spec, :submodules, :spec_create
|
5
5
|
end
|
6
6
|
|
7
7
|
module_function
|
@@ -11,12 +11,14 @@ module Gemgem
|
|
11
11
|
def pkg_dir ; "#{dir}/pkg" ; end
|
12
12
|
def escaped_dir; @escaped_dir ||= Regexp.escape(dir); end
|
13
13
|
|
14
|
-
def init dir, &block
|
14
|
+
def init dir, options={}, &block
|
15
15
|
self.dir = dir
|
16
|
-
$LOAD_PATH.unshift("#{dir}/lib")
|
17
16
|
ENV['RUBYLIB'] = "#{dir}/lib:#{ENV['RUBYLIB']}"
|
18
17
|
ENV['PATH'] = "#{dir}/bin:#{ENV['PATH']}"
|
18
|
+
self.submodules = options[:submodules] || []
|
19
19
|
self.spec_create = block
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift("#{dir}/lib", *submodules_libs)
|
20
22
|
end
|
21
23
|
|
22
24
|
def create
|
@@ -115,6 +117,7 @@ module Gemgem
|
|
115
117
|
SimpleCov.start do
|
116
118
|
add_filter('test/')
|
117
119
|
add_filter('test.rb')
|
120
|
+
submodules_libs.each(&method(:add_filter))
|
118
121
|
end
|
119
122
|
end
|
120
123
|
|
@@ -159,11 +162,15 @@ module Gemgem
|
|
159
162
|
end
|
160
163
|
|
161
164
|
def strip_home_path path
|
162
|
-
path.sub(ENV['HOME']
|
165
|
+
path.sub(/\A#{Regexp.escape(ENV['HOME'])}\//, '~/')
|
163
166
|
end
|
164
167
|
|
165
168
|
def strip_cwd_path path
|
166
|
-
path.sub(Dir.pwd
|
169
|
+
path.sub(/\A#{Regexp.escape(Dir.pwd)}\//, '')
|
170
|
+
end
|
171
|
+
|
172
|
+
def submodules_libs
|
173
|
+
submodules.map{ |path| "#{dir}/#{path}/lib" }
|
167
174
|
end
|
168
175
|
|
169
176
|
def git *args
|
@@ -221,7 +228,8 @@ module Gemgem
|
|
221
228
|
|
222
229
|
def gem_files
|
223
230
|
@gem_files ||= all_files.reject{ |f|
|
224
|
-
f =~
|
231
|
+
f =~ submodules_pattern ||
|
232
|
+
(f =~ ignored_pattern && !git_files.include?(f))
|
225
233
|
}
|
226
234
|
end
|
227
235
|
|
@@ -253,6 +261,15 @@ module Gemgem
|
|
253
261
|
end
|
254
262
|
end
|
255
263
|
|
264
|
+
def submodules_pattern
|
265
|
+
@submodules_pattern ||= if submodules.empty?
|
266
|
+
/^$/
|
267
|
+
else
|
268
|
+
Regexp.new(submodules.map{ |path|
|
269
|
+
"^#{Regexp.escape(path)}/" }.join('|'))
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
256
273
|
def expand_patterns pathes
|
257
274
|
# http://git-scm.com/docs/gitignore
|
258
275
|
pathes.flat_map{ |path|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
require 'rib/test'
|
3
|
+
require 'rib/core/last_value'
|
4
|
+
|
5
|
+
copy :last_value do
|
6
|
+
would 'set last_value' do
|
7
|
+
mock(@shell).get_input{'Rib.last_value'}
|
8
|
+
mock(@shell).get_input{'10**2'}
|
9
|
+
mock(@shell).get_input{'Rib.last_value'}
|
10
|
+
@shell.loop_once.should.eq [nil, nil]
|
11
|
+
@shell.loop_once
|
12
|
+
@shell.loop_once.should.eq [100, nil]
|
13
|
+
end
|
14
|
+
|
15
|
+
would 'set last_exception' do
|
16
|
+
stub(@shell).puts{}.with_any_args
|
17
|
+
mock(@shell).get_input{'XD'}
|
18
|
+
mock(@shell).get_input{'Rib.last_exception'}
|
19
|
+
@shell.loop_once
|
20
|
+
@shell.loop_once.first.should.kind_of?(NameError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe Rib::LastValue do
|
25
|
+
paste :rib
|
26
|
+
|
27
|
+
before do
|
28
|
+
@shell = new_shell
|
29
|
+
stub(@shell).puts(is_a(String)){}
|
30
|
+
stub(Rib).shell{ @shell }
|
31
|
+
end
|
32
|
+
|
33
|
+
test_for Rib::LastValue do
|
34
|
+
paste :last_value
|
35
|
+
end
|
36
|
+
end
|
data/test/core/test_multiline.rb
CHANGED
@@ -7,15 +7,6 @@ describe Rib::Multiline do
|
|
7
7
|
paste :rib
|
8
8
|
paste :setup_multiline
|
9
9
|
|
10
|
-
def check str, err=nil
|
11
|
-
lines = str.split("\n")
|
12
|
-
lines[0...-1].each{ |line|
|
13
|
-
input(line)
|
14
|
-
@shell.loop_once
|
15
|
-
}
|
16
|
-
input_done(lines.last, err)
|
17
|
-
end
|
18
|
-
|
19
10
|
test_for Rib::Multiline do
|
20
11
|
paste :multiline
|
21
12
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
require 'rib/test'
|
3
|
+
require 'rib/more/anchor'
|
4
|
+
require 'rib/core/multiline'
|
5
|
+
require 'rib/test/multiline'
|
6
|
+
|
7
|
+
describe Rib::Anchor do
|
8
|
+
paste :rib
|
9
|
+
paste :setup_multiline
|
10
|
+
|
11
|
+
def new_shell
|
12
|
+
Rib::Shell.new(:binding => Class.new).before_loop
|
13
|
+
end
|
14
|
+
|
15
|
+
test_for Rib::Anchor, Rib::Multiline do
|
16
|
+
paste :multiline
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |-
|
14
14
|
Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
|
@@ -30,7 +30,6 @@ executables:
|
|
30
30
|
- rib-min
|
31
31
|
- rib-rack
|
32
32
|
- rib-rails
|
33
|
-
- rib-ramaze
|
34
33
|
extensions: []
|
35
34
|
extra_rdoc_files: []
|
36
35
|
files:
|
@@ -49,23 +48,21 @@ files:
|
|
49
48
|
- bin/rib-min
|
50
49
|
- bin/rib-rack
|
51
50
|
- bin/rib-rails
|
52
|
-
- bin/rib-ramaze
|
53
51
|
- lib/rib.rb
|
54
52
|
- lib/rib/all.rb
|
55
53
|
- lib/rib/api.rb
|
56
54
|
- lib/rib/app/auto.rb
|
57
55
|
- lib/rib/app/rack.rb
|
58
56
|
- lib/rib/app/rails.rb
|
59
|
-
- lib/rib/app/ramaze.rb
|
60
57
|
- lib/rib/config.rb
|
61
58
|
- lib/rib/core.rb
|
62
59
|
- lib/rib/core/completion.rb
|
63
60
|
- lib/rib/core/history.rb
|
61
|
+
- lib/rib/core/last_value.rb
|
64
62
|
- lib/rib/core/multiline.rb
|
65
63
|
- lib/rib/core/readline.rb
|
66
64
|
- lib/rib/core/squeeze_history.rb
|
67
65
|
- lib/rib/core/strip_backtrace.rb
|
68
|
-
- lib/rib/core/underscore.rb
|
69
66
|
- lib/rib/debug.rb
|
70
67
|
- lib/rib/extra/autoindent.rb
|
71
68
|
- lib/rib/extra/hirb.rb
|
@@ -74,6 +71,7 @@ files:
|
|
74
71
|
- lib/rib/more.rb
|
75
72
|
- lib/rib/more/anchor.rb
|
76
73
|
- lib/rib/more/bottomup_backtrace.rb
|
74
|
+
- lib/rib/more/caller.rb
|
77
75
|
- lib/rib/more/color.rb
|
78
76
|
- lib/rib/more/edit.rb
|
79
77
|
- lib/rib/more/multiline_history.rb
|
@@ -89,12 +87,14 @@ files:
|
|
89
87
|
- task/gemgem.rb
|
90
88
|
- test/core/test_completion.rb
|
91
89
|
- test/core/test_history.rb
|
90
|
+
- test/core/test_last_value.rb
|
92
91
|
- test/core/test_multiline.rb
|
93
92
|
- test/core/test_readline.rb
|
94
93
|
- test/core/test_squeeze_history.rb
|
95
94
|
- test/core/test_strip_backtrace.rb
|
96
|
-
- test/
|
95
|
+
- test/extra/test_anchor.rb
|
97
96
|
- test/extra/test_autoindent.rb
|
97
|
+
- test/more/test_caller.rb
|
98
98
|
- test/more/test_color.rb
|
99
99
|
- test/more/test_multiline_history.rb
|
100
100
|
- test/test_api.rb
|
@@ -128,12 +128,14 @@ summary: Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
|
|
128
128
|
test_files:
|
129
129
|
- test/core/test_completion.rb
|
130
130
|
- test/core/test_history.rb
|
131
|
+
- test/core/test_last_value.rb
|
131
132
|
- test/core/test_multiline.rb
|
132
133
|
- test/core/test_readline.rb
|
133
134
|
- test/core/test_squeeze_history.rb
|
134
135
|
- test/core/test_strip_backtrace.rb
|
135
|
-
- test/
|
136
|
+
- test/extra/test_anchor.rb
|
136
137
|
- test/extra/test_autoindent.rb
|
138
|
+
- test/more/test_caller.rb
|
137
139
|
- test/more/test_color.rb
|
138
140
|
- test/more/test_multiline_history.rb
|
139
141
|
- test/test_api.rb
|
data/bin/rib-ramaze
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'rib/runner'
|
4
|
-
# create the shell before app to prvent your bundler (if any) kicks in
|
5
|
-
Rib.shell
|
6
|
-
# we need to require anything before loading the app,
|
7
|
-
# and both `rib auto` (true) and `rib-auto` (nil) should work
|
8
|
-
require 'rib/core' if Rib.config.delete(:mimic_irb) != false
|
9
|
-
require 'rib/app/ramaze'
|
10
|
-
# load the app
|
11
|
-
Rib::Ramaze.load
|
12
|
-
Rib::Runner.run(ARGV)
|
data/lib/rib/app/ramaze.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
|
2
|
-
module Rib; end
|
3
|
-
module Rib::Ramaze
|
4
|
-
module_function
|
5
|
-
def load
|
6
|
-
load_ramaze
|
7
|
-
rescue LoadError => e
|
8
|
-
Rib.abort("Error: #{e}", "Is this a Ramaze app?")
|
9
|
-
end
|
10
|
-
|
11
|
-
def load_ramaze
|
12
|
-
# try to produce consistent error message, and yet lazy loading ramaze
|
13
|
-
require start_path unless ramaze?
|
14
|
-
|
15
|
-
require 'ramaze'
|
16
|
-
::Ramaze.options.started = true
|
17
|
-
|
18
|
-
require start_path
|
19
|
-
at_exit{ puts('Ramazement has ended, go in peace.') }
|
20
|
-
end
|
21
|
-
|
22
|
-
def ramaze?
|
23
|
-
File.exist?(start_path)
|
24
|
-
end
|
25
|
-
|
26
|
-
def start_path
|
27
|
-
"#{Rib.config[:prefix]}/start.rb"
|
28
|
-
end
|
29
|
-
end
|
data/lib/rib/core/underscore.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rib'
|
3
|
-
|
4
|
-
module Rib::Underscore
|
5
|
-
extend Rib::Plugin
|
6
|
-
Shell.use(self)
|
7
|
-
|
8
|
-
IVAR = {:_ => :@__rib_result__,
|
9
|
-
:__ => :@__rib_exception__}
|
10
|
-
|
11
|
-
# --------------- Rib API ---------------
|
12
|
-
|
13
|
-
def before_loop
|
14
|
-
return super if Underscore.disabled?
|
15
|
-
eliminate_warnings
|
16
|
-
inject_inspecter
|
17
|
-
super
|
18
|
-
end
|
19
|
-
|
20
|
-
def print_result result
|
21
|
-
return super if Underscore.disabled?
|
22
|
-
bound_object.instance_variable_set(:@__rib_result__, result)
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
|
-
def print_eval_error err
|
27
|
-
return super if Underscore.disabled?
|
28
|
-
bound_object.instance_variable_set(:@__rib_exception__, err)
|
29
|
-
super
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
private
|
35
|
-
def eliminate_warnings
|
36
|
-
IVAR.values.each{ |ivar| bound_object.instance_variable_set(ivar, nil) }
|
37
|
-
end
|
38
|
-
|
39
|
-
def inject_inspecter
|
40
|
-
IVAR.each{ |k, v|
|
41
|
-
bound_singleton.send(:define_method, k){
|
42
|
-
instance_variable_get(v)
|
43
|
-
} unless bound_object.respond_to?(k) # only inject for innocences
|
44
|
-
}
|
45
|
-
rescue TypeError
|
46
|
-
# can't define singleton method for immediate value
|
47
|
-
end
|
48
|
-
|
49
|
-
def bound_singleton
|
50
|
-
if respond_to?(:singleton_class)
|
51
|
-
bound_object.singleton_class
|
52
|
-
else
|
53
|
-
class << bound_object; self; end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'rib/test'
|
3
|
-
require 'rib/core/underscore'
|
4
|
-
|
5
|
-
copy :underscore do
|
6
|
-
would 'set _' do
|
7
|
-
setup
|
8
|
-
mock(@shell).get_input{'_'}
|
9
|
-
mock(@shell).get_input{'10**2'}
|
10
|
-
mock(@shell).get_input{'_'}
|
11
|
-
@shell.loop_once.should.eq [nil, nil]
|
12
|
-
@shell.loop_once
|
13
|
-
@shell.loop_once.should.eq [100, nil]
|
14
|
-
end
|
15
|
-
|
16
|
-
would 'not set _ if already there' do
|
17
|
-
bound = Object.new
|
18
|
-
def bound._
|
19
|
-
'hey'
|
20
|
-
end
|
21
|
-
setup(bound)
|
22
|
-
mock(@shell).get_input{'_'}
|
23
|
-
mock(@shell).get_input{'10**2'}
|
24
|
-
mock(@shell).get_input{'_'}
|
25
|
-
@shell.loop_once.should.eq ['hey', nil]
|
26
|
-
@shell.loop_once
|
27
|
-
@shell.loop_once.should.eq ['hey', nil]
|
28
|
-
end
|
29
|
-
|
30
|
-
would 'set __' do
|
31
|
-
setup
|
32
|
-
stub(@shell).puts{}.with_any_args
|
33
|
-
mock(@shell).get_input{'XD'}
|
34
|
-
mock(@shell).get_input{'__'}
|
35
|
-
@shell.loop_once
|
36
|
-
@shell.loop_once.first.should.kind_of?(NameError)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe Rib::Underscore do
|
41
|
-
paste :rib
|
42
|
-
|
43
|
-
def setup bound=Object.new
|
44
|
-
@shell = Rib::Shell.new(
|
45
|
-
:binding => bound.instance_eval{binding}).before_loop
|
46
|
-
stub(@shell).puts(is_a(String)){}
|
47
|
-
end
|
48
|
-
|
49
|
-
test_for Rib::Underscore do
|
50
|
-
paste :underscore
|
51
|
-
end
|
52
|
-
end
|