binding.repl 1.0.4.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.bundle/config +3 -0
- data/.gitignore +6 -0
- data/.travis.yml +12 -0
- data/ChangeLog.txt +9 -0
- data/Gemfile +7 -0
- data/MIT-LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +8 -0
- data/binding.repl.gemspec +12 -0
- data/examples/ir.rb +2 -0
- data/examples/irb.rb +3 -0
- data/examples/pry.rb +2 -0
- data/examples/rib.rb +2 -0
- data/examples/ripl.rb +2 -0
- data/lib/binding.repl.rb +84 -77
- data/lib/binding.repl/exitvalue.rb +40 -0
- data/lib/binding.repl/{core_ext → mpatch}/binding.rb +0 -4
- data/lib/binding.repl/repls/ir.rb +7 -0
- data/lib/binding.repl/repls/irb.rb +7 -8
- data/lib/binding.repl/repls/irb/irb.rb +119 -0
- data/lib/binding.repl/repls/pry.rb +7 -7
- data/lib/binding.repl/repls/rib.rb +8 -5
- data/lib/binding.repl/repls/ripl.rb +3 -3
- data/lib/binding.repl/version.rb +1 -4
- data/test/binding_repl_auto_test.rb +41 -0
- data/test/binding_repl_irb_test.rb +16 -0
- data/test/binding_repl_rib_test.rb +13 -0
- data/test/binding_repl_ripl_test.rb +13 -0
- data/test/binding_repl_test.rb +24 -0
- data/test/binding_test.rb +12 -0
- data/test/setup.rb +5 -0
- data/test/support/mock.rb +15 -0
- data/test/support/repls.rb +55 -0
- metadata +37 -17
- data/LEGAL.txt +0 -20
- data/doc/disableatruntime.md +0 -23
- data/doc/exit_values.md +0 -53
- data/doc/runtimeoptions.md +0 -46
- data/doc/shellvariables.md +0 -10
- data/lib/binding.repl/env.rb +0 -10
- data/lib/binding.repl/exit_value.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efdbef0970558803105b9fd7dded3ffdf38fb120
|
4
|
+
data.tar.gz: ff8b0424aeba9a3b5cc299a97a66a553e8ed9735
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f31c9e90899e97cc0834b3cf2ca36c9ebdbe3aa36f16e681388d9ff68ed3bb3b42c1961728f83518398504ba7c2fadeae081a3d44cd7c03b15fd2c4c31176f38
|
7
|
+
data.tar.gz: 6fb64450c68878cecbeee80d12af3f3224fbc854c0d5030b919948a8822f6d0262e3d4e46711caf9c476578d4ad78751f3128d8ad42047ae8cc93ff1a3bc8080
|
data/.bundle/config
ADDED
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/ChangeLog.txt
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 rpag
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
__binding.repl__
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/rpag/binding.repl.svg?branch=master)](https://travis-ci.org/rpag/binding.repl)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/rpag/binding.repl/badges/gpa.svg)](https://codeclimate.com/github/rpag/binding.repl)
|
5
|
+
|
6
|
+
"binding.pry" for every ruby repl.
|
7
|
+
|
8
|
+
__Features__
|
9
|
+
|
10
|
+
* Start the repl pry, irb, ripl, rib or ir at runtime
|
11
|
+
* Auto-discover and start the first found repl at runtime
|
12
|
+
* Require of a repl is delayed until you call "binding.repl.<repl name>"
|
13
|
+
* Require of a repl is never duplicated
|
14
|
+
* Easily extended to support new repls
|
15
|
+
|
16
|
+
__Examples__
|
17
|
+
|
18
|
+
__1.__
|
19
|
+
|
20
|
+
An example of how you can start a repl of your choice in a
|
21
|
+
[sinatra](https://github.com/sinatra/sinatra) web application:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
get "/greet" do
|
25
|
+
binding.repl.{pry,irb,ripl,rib,ir}
|
26
|
+
["hello", "hola"].sample
|
27
|
+
end
|
28
|
+
```
|
29
|
+
__2.__
|
30
|
+
|
31
|
+
Auto-discover and start the first found repl:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
class Apple
|
35
|
+
# auto discover and start the first found repl.
|
36
|
+
binding.repl.auto
|
37
|
+
|
38
|
+
# same as 'binding.repl.auto' but with less characters to type.
|
39
|
+
binding.repl!
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
__Install__
|
44
|
+
|
45
|
+
rubygems:
|
46
|
+
|
47
|
+
gem install binding.repl
|
48
|
+
|
49
|
+
git:
|
50
|
+
|
51
|
+
git clone https://github.com/rpag/binding.repl.git
|
52
|
+
cd binding.repl
|
53
|
+
gem build binding.repl.gemspec
|
54
|
+
gem install *.gem
|
55
|
+
|
56
|
+
__License__
|
57
|
+
|
58
|
+
See MIT-LICENSE.txt file.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.push 'lib'
|
2
|
+
Kernel.require 'binding.repl/version'
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'binding.repl'
|
5
|
+
spec.version = BindingRepl::VERSION
|
6
|
+
spec.authors = ['rpag']
|
7
|
+
spec.email = ['rpag@singletonclass.com']
|
8
|
+
spec.summary = '"binding.pry" for every ruby repl'
|
9
|
+
spec.homepage = 'https://github.com/rpag/binding.repl'
|
10
|
+
spec.files = `git ls-files`.split($/)
|
11
|
+
spec.license = 'MIT'
|
12
|
+
end
|
data/examples/ir.rb
ADDED
data/examples/irb.rb
ADDED
data/examples/pry.rb
ADDED
data/examples/rib.rb
ADDED
data/examples/ripl.rb
ADDED
data/lib/binding.repl.rb
CHANGED
@@ -1,14 +1,39 @@
|
|
1
1
|
class BindingRepl
|
2
|
-
|
3
|
-
LOOKUP.default = [proc { true }, proc { :'binding.repl.unknown_console' }]
|
4
|
-
DEFAULT_AUTO_ORDER = ["pry", "ripl", "rib", "irb"].freeze
|
2
|
+
DEFAULT_AUTO = ['pry', 'irb', 'ripl', 'rib', 'ir']
|
5
3
|
|
6
|
-
|
7
|
-
|
4
|
+
#
|
5
|
+
# @param [String] name
|
6
|
+
# the name of a repl, callable through `binding.repl.<name>`.
|
7
|
+
#
|
8
|
+
# @param [Array<Proc, Proc>] valuep
|
9
|
+
# a Proc pair that defines an initializer and a runner for a repl.
|
10
|
+
#
|
11
|
+
# @raise
|
12
|
+
# (see BindingRepl#start)
|
13
|
+
#
|
14
|
+
def self.[]=(name, valuep)
|
15
|
+
define_method(name) do |options = {}|
|
16
|
+
start(name.to_s, @binding, valuep, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# @return [Array<String>]
|
22
|
+
# returns an array of repl names.
|
23
|
+
#
|
24
|
+
def self.auto
|
25
|
+
@auto ||= DEFAULT_AUTO
|
8
26
|
end
|
9
27
|
|
10
|
-
|
11
|
-
|
28
|
+
#
|
29
|
+
# @param [Array<String>] list
|
30
|
+
# defines a new order for the {#auto} method.
|
31
|
+
#
|
32
|
+
# @return [Array<String>]
|
33
|
+
# returns the argument.
|
34
|
+
#
|
35
|
+
def self.auto=(list)
|
36
|
+
@auto = list
|
12
37
|
end
|
13
38
|
|
14
39
|
#
|
@@ -32,7 +57,7 @@ class BindingRepl
|
|
32
57
|
|
33
58
|
#
|
34
59
|
# disable binding.repl
|
35
|
-
# future calls to `binding.repl.{auto,
|
60
|
+
# future calls to `binding.repl.{auto,fry,rib,pry,ripl}` become a no-op.
|
36
61
|
#
|
37
62
|
# @return [true]
|
38
63
|
#
|
@@ -41,93 +66,75 @@ class BindingRepl
|
|
41
66
|
end
|
42
67
|
|
43
68
|
#
|
44
|
-
#
|
45
|
-
#
|
69
|
+
# @param [Binding] binding
|
70
|
+
# a Binding object.
|
46
71
|
#
|
47
|
-
#
|
48
|
-
#
|
72
|
+
# @return [BindingRepl]
|
73
|
+
# returns an instance of BindingRepl.
|
49
74
|
#
|
50
|
-
# @param [Proc] runner
|
51
|
-
# a Proc that is expected to start a repl.
|
52
|
-
# the Proc is passed a `Binding` and a Hash of options.
|
53
|
-
#
|
54
|
-
# @return [nil, Symbol]
|
55
|
-
# returns the return value of a method definition.
|
56
|
-
# on 2.1+ that could be the method name as a symbol, or nil on <2.1.
|
57
|
-
#
|
58
|
-
def self.add(console, initializer, runner)
|
59
|
-
LOOKUP[console.to_s] = [initializer, runner]
|
60
|
-
define_method(console) do |options = {}|
|
61
|
-
value = run_console(console, options)
|
62
|
-
value.failure? ? die(console) : value
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
75
|
def initialize(binding)
|
67
76
|
@binding = binding
|
68
|
-
@
|
77
|
+
@auto = BindingRepl.auto.dup
|
69
78
|
end
|
70
79
|
|
71
80
|
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
# @raise [LoadError]
|
75
|
-
# raises a LoadError when BindingRepl.auto_order is empty.
|
81
|
+
# discovers and starts the first available repl.
|
76
82
|
#
|
77
83
|
# @raise [LoadError]
|
78
|
-
#
|
79
|
-
# via Kernel#require.
|
84
|
+
# when no repl can be loaded.
|
80
85
|
#
|
81
86
|
# @return [BindingRepl::ExitValue]
|
82
|
-
# returns an instance of {BindingRepl::ExitValue}
|
87
|
+
# returns an instance of {BindingRepl::ExitValue}.
|
83
88
|
#
|
84
89
|
def auto
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
consoles_str = consoles.join(", ")
|
91
|
-
raise LoadError, "attempts to require any of the following consoles failed: #{consoles_str}"
|
92
|
-
else
|
93
|
-
value
|
90
|
+
@auto.each do |repl_name|
|
91
|
+
begin
|
92
|
+
return public_send(repl_name, {})
|
93
|
+
rescue LoadError, NoMethodError
|
94
|
+
end
|
94
95
|
end
|
96
|
+
raise LoadError, 'failed to require a repl'
|
95
97
|
end
|
96
98
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
consoles.each do |console|
|
104
|
-
value = run_console(console)
|
105
|
-
return value if value.success?
|
106
|
-
end
|
107
|
-
nil
|
99
|
+
#
|
100
|
+
# @return [Boolean]
|
101
|
+
# returns true when BindingRepl is disabled.
|
102
|
+
#
|
103
|
+
def disabled?
|
104
|
+
BindingRepl.disabled?
|
108
105
|
end
|
109
106
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
107
|
+
private
|
108
|
+
#
|
109
|
+
# @param [String] name
|
110
|
+
# the name of a repl.
|
111
|
+
#
|
112
|
+
# @param [Binding] binding
|
113
|
+
# a Binding object.
|
114
|
+
#
|
115
|
+
# @param [Array<Proc, Proc>] valuep
|
116
|
+
# a value pair (initializer and a runner)
|
117
|
+
#
|
118
|
+
# @param [Hash] options
|
119
|
+
# options Hash that are forwarded to the repl.
|
120
|
+
#
|
121
|
+
def start(name, binding, valuep, options)
|
122
|
+
if disabled?
|
123
|
+
return BindingRepl::ExitValue.disabled
|
119
124
|
end
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
125
|
+
init, runner = valuep[0..1]
|
126
|
+
init.call(name)
|
127
|
+
BindingRepl::ExitValue.new runner.call(binding, options)
|
128
|
+
rescue LoadError => e
|
129
|
+
raise e, "failed to require '#{name}' repl"
|
124
130
|
end
|
125
131
|
end
|
126
|
-
|
127
|
-
require_relative
|
128
|
-
require_relative
|
129
|
-
require_relative
|
130
|
-
require_relative
|
131
|
-
require_relative
|
132
|
-
require_relative
|
133
|
-
require_relative
|
132
|
+
|
133
|
+
require_relative 'binding.repl/version'
|
134
|
+
require_relative 'binding.repl/exitvalue'
|
135
|
+
require_relative 'binding.repl/mpatch/binding'
|
136
|
+
require_relative 'binding.repl/repls/irb'
|
137
|
+
require_relative 'binding.repl/repls/ripl'
|
138
|
+
require_relative 'binding.repl/repls/rib'
|
139
|
+
require_relative 'binding.repl/repls/pry'
|
140
|
+
require_relative 'binding.repl/repls/ir'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class BindingRepl::ExitValue
|
2
|
+
MAP = {
|
3
|
+
:disabled => :'binding.repl.disabled'
|
4
|
+
}
|
5
|
+
|
6
|
+
#
|
7
|
+
# @return [BindingRepl::ExitValue]
|
8
|
+
# returns a disabled exit value.
|
9
|
+
#
|
10
|
+
def self.disabled
|
11
|
+
new(MAP[:disabled])
|
12
|
+
end
|
13
|
+
|
14
|
+
#
|
15
|
+
# @param [BasicObject, Object] an object
|
16
|
+
# an object who has been returned by a repl.
|
17
|
+
#
|
18
|
+
# @return [BindingRepl::ExitValue]
|
19
|
+
# returns an instance of {BindingRepl::ExitValue}.
|
20
|
+
#
|
21
|
+
def initialize(object)
|
22
|
+
@object = object
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# @return [Object, BasicObject]
|
27
|
+
# returns the object returned as an exit value by a repl.
|
28
|
+
#
|
29
|
+
def object
|
30
|
+
@object
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# @return [Boolean]
|
35
|
+
# returns a true value if the exit value is returned while binding.repl is disabled.
|
36
|
+
#
|
37
|
+
def disabled?
|
38
|
+
MAP[:disabled].equal?(@object)
|
39
|
+
end
|
40
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
initializer = lambda do
|
2
|
-
require
|
3
|
-
|
1
|
+
initializer = lambda do |name|
|
2
|
+
require(name) unless defined?(IRB)
|
3
|
+
require_relative 'irb/irb'
|
4
|
+
IRB.conf.merge!(BindingRepl::IRB::MAP)
|
4
5
|
end
|
5
6
|
runner = lambda do |binding, options|
|
6
|
-
|
7
|
-
IRB.conf[:MAIN_CONTEXT] = irb.context
|
8
|
-
trap("SIGINT") { irb.signal_handle }
|
9
|
-
catch(:IRB_EXIT) { irb.eval_input }
|
7
|
+
BindingRepl::IRB.new(binding, options).repl
|
10
8
|
end
|
11
|
-
BindingRepl
|
9
|
+
BindingRepl['irb'] = [initializer, runner]
|
10
|
+
|
@@ -0,0 +1,119 @@
|
|
1
|
+
class BindingRepl::IRB
|
2
|
+
MAP = {
|
3
|
+
IRB_NAME: 'irb' ,
|
4
|
+
MATH_MODE: nil ,
|
5
|
+
INSPECT_MODE: true ,
|
6
|
+
IRB_RC: nil ,
|
7
|
+
BACK_TRACE_LIMIT: 17 ,
|
8
|
+
USE_LOADER: false ,
|
9
|
+
USE_TRACER: false ,
|
10
|
+
IGNORE_SIGINT: false ,
|
11
|
+
IGNORE_EOF: false ,
|
12
|
+
DEBUG_LEVEL: 0 ,
|
13
|
+
PROMPT_MODE: :DEFAULT ,
|
14
|
+
LC_MESSAGES: '' ,
|
15
|
+
PROMPT: {
|
16
|
+
:NULL => {
|
17
|
+
:PROMPT_I => nil,
|
18
|
+
:PROMPT_N => nil,
|
19
|
+
:PROMPT_S => nil,
|
20
|
+
:PROMPT_C => nil,
|
21
|
+
:RETURN => "%s\n"
|
22
|
+
},
|
23
|
+
:DEFAULT => {
|
24
|
+
:PROMPT_I => "%N(%m):%03n:%i> ",
|
25
|
+
:PROMPT_N => "%N(%m):%03n:%i> ",
|
26
|
+
:PROMPT_S => "%N(%m):%03n:%i%l ",
|
27
|
+
:PROMPT_C => "%N(%m):%03n:%i* ",
|
28
|
+
:RETURN => "=> %s\n"
|
29
|
+
},
|
30
|
+
:CLASSIC => {
|
31
|
+
:PROMPT_I => "%N(%m):%03n:%i> ",
|
32
|
+
:PROMPT_N => "%N(%m):%03n:%i> ",
|
33
|
+
:PROMPT_S => "%N(%m):%03n:%i%l ",
|
34
|
+
:PROMPT_C => "%N(%m):%03n:%i* ",
|
35
|
+
:RETURN => "%s\n"
|
36
|
+
},
|
37
|
+
:SIMPLE => {
|
38
|
+
:PROMPT_I => ">> ",
|
39
|
+
:PROMPT_N => ">> ",
|
40
|
+
:PROMPT_S => nil,
|
41
|
+
:PROMPT_C => "?> ",
|
42
|
+
:RETURN => "=> %s\n"
|
43
|
+
},
|
44
|
+
:INF_RUBY => {
|
45
|
+
:PROMPT_I => "%N(%m):%03n:%i> ",
|
46
|
+
:PROMPT_N => nil,
|
47
|
+
:PROMPT_S => nil,
|
48
|
+
:PROMPT_C => nil,
|
49
|
+
:RETURN => "%s\n",
|
50
|
+
:AUTO_INDENT => true
|
51
|
+
},
|
52
|
+
:XMP => {
|
53
|
+
:PROMPT_I => nil,
|
54
|
+
:PROMPT_N => nil,
|
55
|
+
:PROMPT_S => nil,
|
56
|
+
:PROMPT_C => nil,
|
57
|
+
:RETURN => " ==>%s\n"
|
58
|
+
},
|
59
|
+
:'binding.repl' => {
|
60
|
+
:PROMPT_I => "% ",
|
61
|
+
:PROMPT_N => "% ",
|
62
|
+
:PROMPT_S => nil,
|
63
|
+
:PROMPT_C => "?> ",
|
64
|
+
:RETURN => "=> %s\n"
|
65
|
+
},
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
#
|
70
|
+
# @param
|
71
|
+
# (see BindingRepl::IRB#initialize)
|
72
|
+
#
|
73
|
+
# @return
|
74
|
+
# (see BindingRepl::IRB#repl)
|
75
|
+
#
|
76
|
+
def self.start(binding, options = {})
|
77
|
+
new(binding, options).repl
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# @param [Binding] binding
|
82
|
+
# a Binding object.
|
83
|
+
#
|
84
|
+
# @param [Hash] options
|
85
|
+
# a Hash of options.
|
86
|
+
# see {BindingRepl::IRB::MAP} for a list of possibles.
|
87
|
+
#
|
88
|
+
def initialize(binding, options = {})
|
89
|
+
@binding = binding
|
90
|
+
@options = ::IRB.conf.merge!(options)
|
91
|
+
@ws = ::IRB::WorkSpace.new(@binding)
|
92
|
+
@repl = ::IRB::Irb.new(@ws)
|
93
|
+
end
|
94
|
+
|
95
|
+
#
|
96
|
+
# read, eval, print, and loop.
|
97
|
+
#
|
98
|
+
# @return [BasicObject, Object]
|
99
|
+
# returns a repl exit value.
|
100
|
+
#
|
101
|
+
def repl
|
102
|
+
setup
|
103
|
+
signal_handle
|
104
|
+
eval_input
|
105
|
+
end
|
106
|
+
|
107
|
+
private
|
108
|
+
def setup
|
109
|
+
::IRB.conf[:MAIN_CONTEXT] = @repl.context
|
110
|
+
end
|
111
|
+
|
112
|
+
def signal_handle
|
113
|
+
trap(:SIGINT) { @repl.signal_handle }
|
114
|
+
end
|
115
|
+
|
116
|
+
def eval_input
|
117
|
+
catch(:IRB_EXIT) { @repl.eval_input }
|
118
|
+
end
|
119
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
initializer = lambda do
|
2
|
-
require
|
3
|
-
end
|
4
|
-
runner = lambda do |binding, options|
|
5
|
-
|
6
|
-
end
|
7
|
-
BindingRepl
|
1
|
+
initializer = lambda do |name|
|
2
|
+
require(name) unless defined?(Pry)
|
3
|
+
end
|
4
|
+
runner = lambda do |binding, options|
|
5
|
+
Pry.start(binding, options)
|
6
|
+
end
|
7
|
+
BindingRepl['pry'] = [initializer, runner]
|
@@ -1,8 +1,11 @@
|
|
1
|
-
initializer = lambda do
|
2
|
-
|
3
|
-
|
1
|
+
initializer = lambda do |name|
|
2
|
+
unless defined?(Rib)
|
3
|
+
require 'rib'
|
4
|
+
require 'rib/more/anchor'
|
5
|
+
end
|
4
6
|
end
|
5
7
|
runner = lambda do |binding, options|
|
6
|
-
Rib.anchor
|
8
|
+
Rib.anchor(binding, options)
|
7
9
|
end
|
8
|
-
BindingRepl
|
10
|
+
BindingRepl['rib'] = [initializer, runner]
|
11
|
+
|
@@ -1,7 +1,7 @@
|
|
1
|
-
initializer = lambda do
|
2
|
-
require
|
1
|
+
initializer = lambda do |name|
|
2
|
+
require(name) unless defined?(Ripl)
|
3
3
|
end
|
4
4
|
runner = lambda do |binding, options|
|
5
5
|
Ripl.start options.merge(binding: binding)
|
6
6
|
end
|
7
|
-
BindingRepl
|
7
|
+
BindingRepl['ripl'] = [initializer, runner]
|
data/lib/binding.repl/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
class BindingReplAutoTest < Minitest::Test
|
3
|
+
include BindingRepl::Mock
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
BindingRepl.auto = nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def teardown
|
10
|
+
super
|
11
|
+
BindingRepl.auto = nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_ripl_as_second_match
|
15
|
+
BindingRepl.auto = ['example', 'ripl']
|
16
|
+
expect(Ripl).to receive(:start).with(binding: instance_of(Binding))
|
17
|
+
binding.repl.auto
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_no_match
|
21
|
+
BindingRepl.auto = ['ry', 'bu']
|
22
|
+
assert_raises(LoadError) { binding.repl.auto }
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_empty
|
26
|
+
BindingRepl.auto = []
|
27
|
+
assert_raises(LoadError) { binding.repl.auto }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_disable
|
31
|
+
BindingRepl.disable!
|
32
|
+
assert_equal binding.repl.auto.disabled?, true
|
33
|
+
ensure
|
34
|
+
BindingRepl.enable!
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_shortcut_method_repl!
|
38
|
+
expect_any_instance_of(BindingRepl).to receive(:auto)
|
39
|
+
binding.repl!
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
class BindingReplIrbTest < Minitest::Test
|
3
|
+
include BindingRepl::Mock
|
4
|
+
def test_irb
|
5
|
+
expect_any_instance_of(IRB::Irb).to receive(:eval_input)
|
6
|
+
binding.repl.irb
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_irb_set_custom_option
|
10
|
+
irbrc = IRB.conf[:IRB_RC]
|
11
|
+
expect_any_instance_of(IRB::Irb).to receive(:eval_input)
|
12
|
+
binding.repl.irb IRB_RC: '/home/nobody/.irbrc'
|
13
|
+
assert_equal '/home/nobody/.irbrc', IRB.conf[:IRB_RC]
|
14
|
+
IRB.conf[:IRB_RC] = irbrc
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative 'setup'
|
2
|
+
class BindingReplRibTest < Minitest::Test
|
3
|
+
include BindingRepl::Mock
|
4
|
+
def test_rib
|
5
|
+
expect(Rib).to receive(:anchor).with(instance_of(Binding), {})
|
6
|
+
binding.repl.rib
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_rib_with_options
|
10
|
+
expect(Rib).to receive(:anchor).with(instance_of(Binding), {prompt: ">>"})
|
11
|
+
binding.repl.rib prompt: ">>"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative "setup"
|
2
|
+
class BindingReplRiplTest < Minitest::Test
|
3
|
+
include BindingRepl::Mock
|
4
|
+
def test_ripl
|
5
|
+
expect(Ripl).to receive(:start).with({binding: instance_of(Binding)})
|
6
|
+
binding.repl.ripl
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_ripl_with_options
|
10
|
+
expect(Ripl).to receive(:start).with({binding: instance_of(Binding), riplrc: false})
|
11
|
+
binding.repl.ripl riplrc: false
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative "setup"
|
2
|
+
class BindingReplTest < Minitest::Test
|
3
|
+
def setup
|
4
|
+
@before = BindingRepl.auto.dup
|
5
|
+
end
|
6
|
+
|
7
|
+
def teardown
|
8
|
+
BindingRepl.auto = @before
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_default_return_value_of_auto
|
12
|
+
assert_equal BindingRepl::DEFAULT_AUTO, BindingRepl.auto
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_set_of_new_auto
|
16
|
+
BindingRepl.auto = ['a', 'b']
|
17
|
+
assert_equal ['a', 'b'], BindingRepl.auto
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_set_of_nil_on_auto
|
21
|
+
BindingRepl.auto = nil
|
22
|
+
assert_equal BindingRepl::DEFAULT_AUTO, BindingRepl.auto
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require_relative "setup"
|
2
|
+
class BindingTest < Minitest::Test
|
3
|
+
include BindingRepl::Mock
|
4
|
+
def test_return_value_of_repl
|
5
|
+
assert_instance_of BindingRepl, binding.repl
|
6
|
+
end
|
7
|
+
|
8
|
+
def test_delegate_to_auto
|
9
|
+
expect_any_instance_of(BindingRepl).to receive(:auto)
|
10
|
+
binding.repl!
|
11
|
+
end
|
12
|
+
end
|
data/test/setup.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module IRB
|
2
|
+
@CONF = {}
|
3
|
+
|
4
|
+
def self.conf
|
5
|
+
@CONF
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.setup(ap = nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.irb_at_exit
|
12
|
+
end
|
13
|
+
|
14
|
+
class WorkSpace
|
15
|
+
def initialize(b, other=nil)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Irb
|
20
|
+
def initialize(*)
|
21
|
+
end
|
22
|
+
|
23
|
+
def context
|
24
|
+
binding
|
25
|
+
end
|
26
|
+
|
27
|
+
def eval_input
|
28
|
+
end
|
29
|
+
|
30
|
+
def signal_handle
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Ir
|
36
|
+
class Tty
|
37
|
+
def initialize(options = {})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class Ripl
|
43
|
+
def self.start(options = {})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Pry
|
48
|
+
def self.start(binding, options = {})
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Rib
|
53
|
+
def self.anchor(binding, options = {})
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,39 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binding.repl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- rpag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03
|
11
|
+
date: 2014-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description:
|
14
14
|
email:
|
15
|
-
-
|
15
|
+
- rpag@singletonclass.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
-
|
21
|
-
-
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
20
|
+
- ".bundle/config"
|
21
|
+
- ".gitignore"
|
22
|
+
- ".travis.yml"
|
23
|
+
- ChangeLog.txt
|
24
|
+
- Gemfile
|
25
|
+
- MIT-LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- binding.repl.gemspec
|
29
|
+
- examples/ir.rb
|
30
|
+
- examples/irb.rb
|
31
|
+
- examples/pry.rb
|
32
|
+
- examples/rib.rb
|
33
|
+
- examples/ripl.rb
|
25
34
|
- lib/binding.repl.rb
|
26
|
-
- lib/binding.repl/
|
27
|
-
- lib/binding.repl/
|
28
|
-
- lib/binding.repl/
|
35
|
+
- lib/binding.repl/exitvalue.rb
|
36
|
+
- lib/binding.repl/mpatch/binding.rb
|
37
|
+
- lib/binding.repl/repls/ir.rb
|
29
38
|
- lib/binding.repl/repls/irb.rb
|
39
|
+
- lib/binding.repl/repls/irb/irb.rb
|
30
40
|
- lib/binding.repl/repls/pry.rb
|
31
41
|
- lib/binding.repl/repls/rib.rb
|
32
42
|
- lib/binding.repl/repls/ripl.rb
|
33
43
|
- lib/binding.repl/version.rb
|
34
|
-
|
44
|
+
- test/binding_repl_auto_test.rb
|
45
|
+
- test/binding_repl_irb_test.rb
|
46
|
+
- test/binding_repl_rib_test.rb
|
47
|
+
- test/binding_repl_ripl_test.rb
|
48
|
+
- test/binding_repl_test.rb
|
49
|
+
- test/binding_test.rb
|
50
|
+
- test/setup.rb
|
51
|
+
- test/support/mock.rb
|
52
|
+
- test/support/repls.rb
|
53
|
+
homepage: https://github.com/rpag/binding.repl
|
35
54
|
licenses:
|
36
|
-
-
|
55
|
+
- MIT
|
37
56
|
metadata: {}
|
38
57
|
post_install_message:
|
39
58
|
rdoc_options: []
|
@@ -43,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
43
62
|
requirements:
|
44
63
|
- - ">="
|
45
64
|
- !ruby/object:Gem::Version
|
46
|
-
version:
|
65
|
+
version: '0'
|
47
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
67
|
requirements:
|
49
68
|
- - ">="
|
@@ -54,5 +73,6 @@ rubyforge_project:
|
|
54
73
|
rubygems_version: 2.2.2
|
55
74
|
signing_key:
|
56
75
|
specification_version: 4
|
57
|
-
summary: binding.
|
76
|
+
summary: '"binding.pry" for every ruby repl'
|
58
77
|
test_files: []
|
78
|
+
has_rdoc:
|
data/LEGAL.txt
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
This is free and unencumbered software released into the public domain.
|
2
|
-
|
3
|
-
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
-
distribute this software, either in source code form or as a compiled
|
5
|
-
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
-
means.
|
7
|
-
|
8
|
-
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
-
of this software dedicate any and all copyright interest in the
|
10
|
-
software to the public domain.
|
11
|
-
|
12
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
13
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
14
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
15
|
-
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
16
|
-
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
17
|
-
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
18
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
19
|
-
|
20
|
-
For more information, please refer to <http://unlicense.org/>
|
data/doc/disableatruntime.md
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
__ENABLE OR DISABLE AT RUNTIME__
|
2
|
-
|
3
|
-
binding.repl can be enabled or disabled at runtime. <br>
|
4
|
-
the default state is 'enabled'.
|
5
|
-
|
6
|
-
__DISABLE__
|
7
|
-
|
8
|
-
```ruby
|
9
|
-
class Foo
|
10
|
-
BindingRepl.disable!
|
11
|
-
value = binding.repl.irb
|
12
|
-
p value.disabled? # => true
|
13
|
-
end
|
14
|
-
```
|
15
|
-
|
16
|
-
__ENABLE__
|
17
|
-
|
18
|
-
```ruby
|
19
|
-
class Foo
|
20
|
-
BindingRepl.enable!
|
21
|
-
value = binding.repl.irb # opens irb on 'Foo'.
|
22
|
-
end
|
23
|
-
```
|
data/doc/exit_values.md
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
__EXIT VALUES__
|
2
|
-
|
3
|
-
a repl exit value is returned when `binding.repl.{irb,pry,ripl,rib,auto}` has <br>
|
4
|
-
been called and the repl has exited through "exit".
|
5
|
-
|
6
|
-
__IRB__
|
7
|
-
|
8
|
-
for the IRB example I used a nested IRB session who passes an exit value back <br>
|
9
|
-
through to a parent session:
|
10
|
-
|
11
|
-
```
|
12
|
-
irb(main):001:0> exit "hello world!"
|
13
|
-
=> #<BindingRepl::ExitValue:0x007fb3124e6cc8 @object="hello world!">
|
14
|
-
irb(main):002:0> method(:exit).owner
|
15
|
-
=> IRB::ExtendCommandBundle
|
16
|
-
```
|
17
|
-
|
18
|
-
__pry__
|
19
|
-
|
20
|
-
pry exits a session through a pry command called 'exit'. the difference between a <br>
|
21
|
-
pry command and a ruby method is that a command is not mapped as a ruby method in <br>
|
22
|
-
the active context. like IRB though, the exit command exists partially to allow a <br>
|
23
|
-
value to be passed back to the caller:
|
24
|
-
|
25
|
-
```
|
26
|
-
[1] pry(main)> exit "Hello!"
|
27
|
-
=> #<BindingRepl::ExitValue:0x007fd95d1f4670 @object="Hello!">
|
28
|
-
[2] pry(main)>
|
29
|
-
```
|
30
|
-
|
31
|
-
__rib__
|
32
|
-
|
33
|
-
'exit' inside rib resolves back to `Kernel#exit`. it wasn't immediately clear to me how <br>
|
34
|
-
to send back a custom value with rib but for an example you can see how it works: <br>
|
35
|
-
|
36
|
-
```
|
37
|
-
main(0)>> binding.repl.rib
|
38
|
-
main(1)>> exit
|
39
|
-
=> #<BindingRepl::ExitValue:0x007faab19cc328 @object=#<Object:0x007faab1a16d60>>
|
40
|
-
main(0)>> method(:exit).owner
|
41
|
-
=> Kernel
|
42
|
-
main(0)>>
|
43
|
-
```
|
44
|
-
|
45
|
-
__ripl__
|
46
|
-
|
47
|
-
'ripl' is similar to rib. i couldn't figure out how to pass a value back to the caller <br>
|
48
|
-
and 'exit' resolves to `Kernel#exit` like on rib: <br>
|
49
|
-
|
50
|
-
```
|
51
|
-
>> exit
|
52
|
-
=> #<BindingRepl::ExitValue:0x007faab2d2cee0 @object=nil>
|
53
|
-
```
|
data/doc/runtimeoptions.md
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
__RUNTIME OPTIONS__
|
2
|
-
|
3
|
-
_pry_
|
4
|
-
|
5
|
-
[pry](https://github.com/pry/pry) supports a large number of options for runtime configuration. <br>
|
6
|
-
a full list of options are available at [Pry.start(…) (API Docs)](http://rubydoc.info/github/banister/pry/Pry#start-class_method)
|
7
|
-
|
8
|
-
```ruby
|
9
|
-
class Person
|
10
|
-
binding.repl.pry quiet: true
|
11
|
-
end
|
12
|
-
```
|
13
|
-
|
14
|
-
_rib_
|
15
|
-
|
16
|
-
[rib](https://github.com/godfat/rib) is a little less well known ruby repl that binding.repl supports since v0.8.0. <br>
|
17
|
-
a full list of options are available at [Rib.anchor(…) (API Docs)](http://rdoc.info/github/godfat/rib/Rib/Anchor/Imp#anchor-instance_method)
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
class Alien
|
21
|
-
binding.repl.rib prompt: ">> ", result_prompt: "# => "
|
22
|
-
end
|
23
|
-
```
|
24
|
-
|
25
|
-
_ripl_
|
26
|
-
|
27
|
-
[ripl](https://github.com/cldwalker/ripl) supports (some) runtime configuration. <br>
|
28
|
-
I couldn't find API docs for `Ripl.start(..)`, so I recommend checking out the github
|
29
|
-
page to learn more.
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
class Sink
|
33
|
-
binding.repl.ripl riplrc: false
|
34
|
-
end
|
35
|
-
```
|
36
|
-
|
37
|
-
_note about irb_
|
38
|
-
|
39
|
-
binding.repl doesn't implement runtime options for IRB because it wasn't immediately obvious
|
40
|
-
how IRB is configured at runtime (it looks like `IRB.conf` might be used)
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
class Car
|
44
|
-
binding.repl.irb
|
45
|
-
end
|
46
|
-
```
|
data/doc/shellvariables.md
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
__SHELL ENVIRONMENT VARIABLES__
|
2
|
-
|
3
|
-
__$auto\_order__
|
4
|
-
|
5
|
-
binding.repl can start the first available console through `binding.repl.auto` or the shortcut
|
6
|
-
`binding.repl!`. the default lookup order can be changed by setting an environment variable:
|
7
|
-
|
8
|
-
example
|
9
|
-
|
10
|
-
$ auto_order=pry,irb ruby myscript.rb
|
data/lib/binding.repl/env.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
class BindingRepl::ExitValue
|
2
|
-
STATUS_MAP = {
|
3
|
-
:disabled => :'binding.repl.disabled',
|
4
|
-
:unknown_console => :'binding.repl.unknown_console'
|
5
|
-
}
|
6
|
-
|
7
|
-
def self.load_error_value
|
8
|
-
STATUS_MAP[:unknown_console]
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.disabled_value
|
12
|
-
STATUS_MAP[:disabled]
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :object
|
16
|
-
|
17
|
-
def initialize(object)
|
18
|
-
@object = object
|
19
|
-
end
|
20
|
-
|
21
|
-
def success?
|
22
|
-
not failure?
|
23
|
-
end
|
24
|
-
|
25
|
-
def failure?
|
26
|
-
load_error?
|
27
|
-
end
|
28
|
-
|
29
|
-
def disabled?
|
30
|
-
STATUS_MAP[:disabled] == object
|
31
|
-
end
|
32
|
-
|
33
|
-
def load_error?
|
34
|
-
STATUS_MAP[:unknown_console] == object
|
35
|
-
end
|
36
|
-
end
|