binding.repl 0.1.1.1 → 0.3.0
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.
- data/ChangeLog.txt +20 -0
- data/README.md +30 -19
- data/binding.repl.gemspec +3 -3
- data/lib/binding.repl.rb +66 -30
- data/lib/binding.repl/irb.rb +10 -0
- data/lib/binding.repl/pry.rb +7 -0
- data/lib/binding.repl/ripl.rb +7 -0
- metadata +9 -6
data/ChangeLog.txt
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
== v0.3.0
|
2
|
+
- add Binding.repl.add
|
3
|
+
add a ruby console to binding.repl
|
4
|
+
|
5
|
+
- add lib/binding.repl/{pry,irb,ripl}.rb
|
6
|
+
individual files for each console that use Binding.repl.add
|
7
|
+
|
8
|
+
- modularize design, cleanup internals
|
9
|
+
the anonymous class is gone because constant lookup rules are a
|
10
|
+
pain with anonymous classes. The class we create is available at
|
11
|
+
Binding.repl and nowhere else, though.
|
12
|
+
|
13
|
+
== v0.2.0
|
14
|
+
- call IRB.setup() once
|
15
|
+
fixes #4
|
16
|
+
|
17
|
+
- add binding.repl.auto
|
18
|
+
auto discover the first available console.
|
19
|
+
fixes #3
|
20
|
+
|
1
21
|
== v0.1.1.1
|
2
22
|
- doc improvements
|
3
23
|
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
__DESCRIPTION__
|
9
9
|
|
10
10
|
__binding.repl__ can start a number of different ruby consoles at runtime.
|
11
|
-
IRB, ripl, and
|
11
|
+
IRB, ripl, and pry(of course!) can be invoked at runtime in any context
|
12
12
|
that an instance of `Binding` closes over.
|
13
13
|
|
14
14
|
I owe all credit to John Mair([banisterfiend](https://github.com/banister)),
|
@@ -29,27 +29,36 @@ consoles (if I missed one, open an issue or send an e-note :)).
|
|
29
29
|
__EXAMPLES__
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
class
|
33
|
-
|
34
|
-
binding.repl.ripl # invoke ripl in context of "Foo"
|
35
|
-
binding.repl.irb # invoke irb in context of "Foo"
|
36
|
-
end
|
37
|
-
|
38
|
-
class BlogsController < ActionController::Base
|
39
|
-
def index
|
32
|
+
class BlogsController < ApplicationController
|
33
|
+
def show
|
40
34
|
@blog = Blog.find(params[:id])
|
35
|
+
# invoke pry,irb, or ripl in the context of the 'show' method.
|
41
36
|
binding.repl.{pry,irb,ripl}
|
42
37
|
end
|
43
38
|
end
|
39
|
+
|
40
|
+
class Bar
|
41
|
+
# auto discover the first available console.
|
42
|
+
# default order is: ripl, pry, or irb.
|
43
|
+
binding.repl.auto
|
44
|
+
|
45
|
+
# change default load order
|
46
|
+
Binding.repl.auto_load_order = %w(pry ripl irb)
|
47
|
+
|
48
|
+
# remove "irb" from auto discovery
|
49
|
+
Binding.repl.auto_load_order -= ["irb"]
|
50
|
+
end
|
44
51
|
```
|
45
52
|
|
46
53
|
__NOTES__
|
47
54
|
|
48
|
-
|
55
|
+
_CONFIGURATION_
|
49
56
|
|
50
|
-
|
51
|
-
IRB
|
52
|
-
|
57
|
+
ripl and pry can be customized by passing a set of key-value pairs but
|
58
|
+
IRB isn't as straight forward to configure and I haven't implemented
|
59
|
+
any customization options for it yet.
|
60
|
+
|
61
|
+
ripl can be invoked with options that are forwarded to `Ripl.start(…)`:
|
53
62
|
|
54
63
|
```ruby
|
55
64
|
class Foo
|
@@ -57,7 +66,7 @@ class Foo
|
|
57
66
|
end
|
58
67
|
```
|
59
68
|
|
60
|
-
|
69
|
+
pry can be configured in the same way. options are forwarded to `Pry.start(…)`:
|
61
70
|
|
62
71
|
```ruby
|
63
72
|
class Foo
|
@@ -65,6 +74,8 @@ class Foo
|
|
65
74
|
end
|
66
75
|
```
|
67
76
|
|
77
|
+
_RIPL & IRB_
|
78
|
+
|
68
79
|
I have only used Ripl once(to write this library) and I don't use IRB
|
69
80
|
much anymore. If I can improve support for either please let me know
|
70
81
|
via an issue or pull request/e-note.
|
@@ -72,9 +83,9 @@ via an issue or pull request/e-note.
|
|
72
83
|
|
73
84
|
_DEPENDENCIES_
|
74
85
|
|
75
|
-
binding.repl doesn't depend on anything. it's up to you to meet the
|
76
|
-
dependencies(pry, irb, and/or ripl). `binding.repl.{ripl,pry,irb}`
|
77
|
-
will try to load the appropiate console for you if it looks like it
|
86
|
+
binding.repl doesn't depend on anything. it's up to you to meet the
|
87
|
+
dependencies(pry, irb, and/or ripl). `binding.repl.{ripl,pry,irb}`
|
88
|
+
will try to load the appropiate console for you if it looks like it
|
78
89
|
hasn't been loaded yet.
|
79
90
|
|
80
91
|
__INSTALL__
|
@@ -87,10 +98,10 @@ gem install binding.repl
|
|
87
98
|
|
88
99
|
__CREDIT__
|
89
100
|
|
90
|
-
- [banisterfiend](https://github.com/banister) (John Mair)
|
101
|
+
- [banisterfiend](https://github.com/banister) (John Mair)
|
91
102
|
for pry
|
92
103
|
|
93
|
-
- [Kyrylo](https://github.com/kyrylo) (Kyrylo Silin)
|
104
|
+
- [Kyrylo](https://github.com/kyrylo) (Kyrylo Silin)
|
94
105
|
for his hard work on pry.
|
95
106
|
|
96
107
|
Rest of the Pry team(!!):
|
data/binding.repl.gemspec
CHANGED
@@ -5,9 +5,9 @@ Gem::Specification.new do |spec|
|
|
5
5
|
spec.version = Binding.repl.version
|
6
6
|
spec.authors = ["Robert Gleeson"]
|
7
7
|
spec.email = ["rob@flowof.info"]
|
8
|
-
spec.description = "binding.repl
|
9
|
-
spec.summary =
|
10
|
-
spec.homepage = ""
|
8
|
+
spec.description = "binding.repl: binding.pry for all ruby consoles"
|
9
|
+
spec.summary = spec.description
|
10
|
+
spec.homepage = "https://github.com/robgleeson/binding.repl"
|
11
11
|
spec.license = "MIT"
|
12
12
|
|
13
13
|
spec.files = `git ls-files`.split($/)
|
data/lib/binding.repl.rb
CHANGED
@@ -1,54 +1,90 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
class BindingRepl
|
2
|
+
module BindingMixin
|
3
3
|
def repl
|
4
4
|
Binding.repl.new(self)
|
5
5
|
end
|
6
|
-
|
6
|
+
end
|
7
|
+
|
8
|
+
LOOKUP = {}
|
9
|
+
LOOKUP.default = [proc { true }, proc { :'binding.repl.unknown_console' }]
|
10
|
+
private_constant :LOOKUP
|
11
|
+
|
12
|
+
def self.name
|
13
|
+
"binding.repl"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.inspect
|
17
|
+
name
|
18
|
+
end
|
7
19
|
|
8
20
|
def self.version
|
9
|
-
"0.
|
21
|
+
"0.3.0"
|
10
22
|
end
|
11
23
|
|
12
|
-
def
|
13
|
-
|
24
|
+
def self.add(console, predicate, runner)
|
25
|
+
LOOKUP[console] = [predicate, runner]
|
26
|
+
define_method(console) do |options = {}|
|
27
|
+
exit_value = invoke_console(console, options)
|
28
|
+
error?(exit_value) ? fail!(console) : exit_value
|
29
|
+
end
|
14
30
|
end
|
15
31
|
|
16
|
-
def
|
17
|
-
|
18
|
-
@binding.pry options
|
32
|
+
def self.auto_load_order=(order)
|
33
|
+
@auto_load_order = order
|
19
34
|
end
|
20
35
|
|
21
|
-
def
|
22
|
-
|
23
|
-
Ripl.start options.merge(:binding => @binding)
|
36
|
+
def self.auto_load_order
|
37
|
+
@auto_load_order
|
24
38
|
end
|
25
39
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
catch(:IRB_EXIT) do
|
37
|
-
irb.eval_input
|
40
|
+
def initialize(binding)
|
41
|
+
@binding = binding
|
42
|
+
@lookup = LOOKUP
|
43
|
+
end
|
44
|
+
|
45
|
+
def auto
|
46
|
+
load_order = Binding.repl.auto_load_order
|
47
|
+
load_order.each do |console|
|
48
|
+
exit_value = invoke_console(console.to_sym, {})
|
49
|
+
return exit_value unless error?(exit_value)
|
38
50
|
end
|
51
|
+
raise LoadError, "failed to load consoles: #{load_order.join(", ")}", []
|
39
52
|
end
|
40
53
|
|
41
54
|
private
|
42
|
-
def
|
43
|
-
|
44
|
-
|
55
|
+
def fail!(console)
|
56
|
+
raise LoadError, "the console '#{console}' could not be loaded. is #{console} installed?", []
|
57
|
+
end
|
58
|
+
|
59
|
+
def error?(exit_value)
|
60
|
+
exit_value.to_s.start_with? "binding.repl"
|
61
|
+
end
|
62
|
+
|
63
|
+
def invoke_console(console, options)
|
64
|
+
require_predicate, runner = @lookup[console]
|
65
|
+
require_console(console, require_predicate)
|
66
|
+
runner.call(@binding, options)
|
67
|
+
rescue LoadError
|
68
|
+
:'binding.repl.load_error'
|
69
|
+
end
|
70
|
+
|
71
|
+
def require_console(console, predicate)
|
72
|
+
already_required = predicate.call
|
73
|
+
if !already_required
|
74
|
+
require(console.to_s)
|
75
|
+
# IRB hack.
|
76
|
+
IRB.setup(nil) if console == :irb
|
45
77
|
end
|
46
|
-
rescue LoadError => e
|
47
|
-
raise e, "the ruby console '#{lib}' could not be loaded. is '#{lib}' installed?"
|
48
78
|
end
|
49
79
|
end
|
50
80
|
|
81
|
+
klass = BindingRepl
|
82
|
+
Object.send :remove_const, :BindingRepl
|
51
83
|
Binding.class_eval do
|
52
84
|
define_singleton_method(:repl) { klass }
|
53
|
-
include
|
85
|
+
include klass::BindingMixin
|
86
|
+
repl.auto_load_order = %w(ripl pry irb)
|
54
87
|
end
|
88
|
+
require_relative "binding.repl/pry"
|
89
|
+
require_relative "binding.repl/irb"
|
90
|
+
require_relative "binding.repl/ripl"
|
@@ -0,0 +1,10 @@
|
|
1
|
+
predicate = lambda do
|
2
|
+
defined?(IRB)
|
3
|
+
end
|
4
|
+
runner = lambda do |binding, options|
|
5
|
+
irb = IRB::Irb.new IRB::WorkSpace.new(binding)
|
6
|
+
IRB.conf[:MAIN_CONTEXT] = irb.context
|
7
|
+
trap("SIGINT") { irb.signal_handle }
|
8
|
+
catch(:IRB_EXIT) { irb.eval_input }
|
9
|
+
end
|
10
|
+
Binding.repl.add :irb, predicate, runner
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binding.repl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
-
description: binding.repl
|
46
|
+
description: ! 'binding.repl: binding.pry for all ruby consoles'
|
47
47
|
email:
|
48
48
|
- rob@flowof.info
|
49
49
|
executables: []
|
@@ -59,7 +59,10 @@ files:
|
|
59
59
|
- Rakefile
|
60
60
|
- binding.repl.gemspec
|
61
61
|
- lib/binding.repl.rb
|
62
|
-
|
62
|
+
- lib/binding.repl/irb.rb
|
63
|
+
- lib/binding.repl/pry.rb
|
64
|
+
- lib/binding.repl/ripl.rb
|
65
|
+
homepage: https://github.com/robgleeson/binding.repl
|
63
66
|
licenses:
|
64
67
|
- MIT
|
65
68
|
post_install_message:
|
@@ -80,11 +83,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
83
|
version: '0'
|
81
84
|
segments:
|
82
85
|
- 0
|
83
|
-
hash:
|
86
|
+
hash: 2298799895627227771
|
84
87
|
requirements: []
|
85
88
|
rubyforge_project:
|
86
89
|
rubygems_version: 1.8.23
|
87
90
|
signing_key:
|
88
91
|
specification_version: 3
|
89
|
-
summary: binding.repl
|
92
|
+
summary: ! 'binding.repl: binding.pry for all ruby consoles'
|
90
93
|
test_files: []
|