binding.repl 0.6.0 → 0.7.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 +12 -0
- data/README.md +38 -15
- data/lib/binding.repl.rb +3 -9
- data/lib/binding.repl/console/irb.rb +6 -0
- data/lib/binding.repl/rc.rb +18 -12
- metadata +3 -3
data/ChangeLog.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
== v0.7.0
|
2
|
+
- catch JSON parse errors when reading .binding.repl.rc
|
3
|
+
closes #7
|
4
|
+
|
5
|
+
- no longer read from project-local .binding.repl.rc file
|
6
|
+
the $BINDING_REPL_ORDER environment variable can be set if you
|
7
|
+
want to override the settings defined by $HOME/.binding.repl.rc
|
8
|
+
|
9
|
+
- read shell env var $BINDING_REPL_ORDER
|
10
|
+
set of $BINDING_REPL_ORDER stops the .binding.repl.rc file from
|
11
|
+
being loaded and takes precendence. closes #9.
|
12
|
+
|
1
13
|
== v0.6.0
|
2
14
|
- add Binding.repl.{disable!,enable!}.
|
3
15
|
turn binding.repl.{pry,irb,ripl,auto} into a no-op.
|
data/README.md
CHANGED
@@ -29,14 +29,20 @@ consoles (if I missed one, open an issue or send an e-note :)).
|
|
29
29
|
|
30
30
|
__EXAMPLES__
|
31
31
|
|
32
|
+
_Rails_
|
33
|
+
|
32
34
|
```ruby
|
33
35
|
class BlogsController < ApplicationController
|
34
36
|
def show
|
35
37
|
@blog = Blog.find(params[:id])
|
36
|
-
binding.repl.{pry,irb,ripl}
|
38
|
+
binding.repl.{pry,irb,ripl,auto}
|
37
39
|
end
|
38
40
|
end
|
41
|
+
```
|
39
42
|
|
43
|
+
_Auto discovery_
|
44
|
+
|
45
|
+
```ruby
|
40
46
|
class Bar
|
41
47
|
# auto discover and start the first available console.
|
42
48
|
# default order is: ripl, pry, or irb.
|
@@ -48,7 +54,11 @@ class Bar
|
|
48
54
|
# remove "irb" from auto discovery
|
49
55
|
Binding.repl.auto_load_order -= ["irb"]
|
50
56
|
end
|
57
|
+
```
|
58
|
+
|
59
|
+
_Enable/disable at runtime_
|
51
60
|
|
61
|
+
```ruby
|
52
62
|
class Baz
|
53
63
|
# invoke irb
|
54
64
|
binding.repl.irb
|
@@ -88,32 +98,25 @@ class Foo
|
|
88
98
|
end
|
89
99
|
```
|
90
100
|
|
91
|
-
_DEPENDENCIES_
|
92
|
-
|
93
|
-
binding.repl doesn't depend on anything. it's up to you to meet the
|
94
|
-
dependencies(pry, irb, and/or ripl). `binding.repl.{ripl,pry,irb}`
|
95
|
-
will try to load the appropiate console for you if it looks like it
|
96
|
-
hasn't been loaded yet.
|
97
|
-
|
98
101
|
_WORKING WITH TEAMS_
|
99
102
|
|
100
103
|
people working in teams might have different choices for what ruby
|
101
104
|
console they like to use and __binding.repl__ tries to accomondate by
|
102
|
-
reading a `.binding.repl.rc` file from $HOME or
|
103
|
-
|
105
|
+
reading a `.binding.repl.rc` file from $HOME or by setting a shell
|
106
|
+
environment variable. `binding.repl.rc` is a simple JSON file.
|
104
107
|
|
105
108
|
let's say rob & amy are working on some code together. amy prefers
|
106
|
-
|
109
|
+
ripl, so her `$HOME/.binding.repl.rc` would look like this:
|
107
110
|
```javascript
|
108
111
|
{
|
109
|
-
"auto_load_order": ["
|
112
|
+
"auto_load_order": ["ripl", "irb"]
|
110
113
|
}
|
111
114
|
```
|
112
115
|
|
113
116
|
rob prefers pry, so his `$HOME/.binding.repl.rc` would look like this:
|
114
117
|
```ruby
|
115
118
|
{
|
116
|
-
"auto_load_order": ["pry", "
|
119
|
+
"auto_load_order": ["pry", "irb"]
|
117
120
|
}
|
118
121
|
```
|
119
122
|
|
@@ -122,12 +125,32 @@ they can use `binding.repl.auto`:
|
|
122
125
|
|
123
126
|
```ruby
|
124
127
|
class Foo
|
125
|
-
# starts "irb" in the context of Foo for amy.
|
126
|
-
# starts "pry" in the context of Foo for rob.
|
128
|
+
# starts "irb" in the context of Foo for amy. fall back console is "irb".
|
129
|
+
# starts "pry" in the context of Foo for rob. fall back console is "irb".
|
127
130
|
binding.repl.auto
|
128
131
|
end
|
129
132
|
```
|
130
133
|
|
134
|
+
_SHELL ENVIRONMENT VARIABLES_
|
135
|
+
|
136
|
+
binding.repl can be configured with a couple of shell environment variables.
|
137
|
+
|
138
|
+
```bash
|
139
|
+
# disable trying to read $HOME/.binding.repl.rc
|
140
|
+
export BINDING_REPL_RC=0
|
141
|
+
|
142
|
+
# set the 'auto' load order
|
143
|
+
# takes precendence over $HOME/.binding.repl.rc when set
|
144
|
+
export BINDING_REPL_ORDER=pry,irb
|
145
|
+
```
|
146
|
+
|
147
|
+
_DEPENDENCIES_
|
148
|
+
|
149
|
+
binding.repl doesn't depend on anything. it's up to you to meet the
|
150
|
+
dependencies(pry, irb, and/or ripl). `binding.repl.{ripl,pry,irb}`
|
151
|
+
will try to load the appropiate console for you if it looks like it
|
152
|
+
hasn't been loaded yet.
|
153
|
+
|
131
154
|
__INSTALL__
|
132
155
|
|
133
156
|
ruby 1.9+ only.
|
data/lib/binding.repl.rb
CHANGED
@@ -18,7 +18,7 @@ class BindingRepl
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.version
|
21
|
-
"0.
|
21
|
+
"0.7.0"
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.disabled?
|
@@ -56,8 +56,7 @@ class BindingRepl
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def auto
|
59
|
-
load_order = Binding.repl.auto_load_order
|
60
|
-
exit_value = nil
|
59
|
+
load_order, exit_value = Binding.repl.auto_load_order, nil
|
61
60
|
load_order.each do |console|
|
62
61
|
exit_value = invoke_console(console.to_sym, {})
|
63
62
|
return exit_value unless invoke_failed?(exit_value)
|
@@ -92,8 +91,6 @@ private
|
|
92
91
|
already_required = predicate.call
|
93
92
|
if !already_required
|
94
93
|
require(console.to_s)
|
95
|
-
# IRB hack.
|
96
|
-
IRB.setup(nil) if console == :irb
|
97
94
|
end
|
98
95
|
end
|
99
96
|
end
|
@@ -108,7 +105,4 @@ end
|
|
108
105
|
require_relative "binding.repl/console/pry"
|
109
106
|
require_relative "binding.repl/console/irb"
|
110
107
|
require_relative "binding.repl/console/ripl"
|
111
|
-
|
112
|
-
if ENV["BINDING_REPL_RC"] != "0"
|
113
|
-
require_relative "binding.repl/rc"
|
114
|
-
end
|
108
|
+
require_relative "binding.repl/rc"
|
@@ -1,7 +1,13 @@
|
|
1
1
|
predicate = lambda do
|
2
2
|
defined?(IRB)
|
3
3
|
end
|
4
|
+
|
5
|
+
irb_setup = false
|
4
6
|
runner = lambda do |binding, options|
|
7
|
+
unless irb_setup
|
8
|
+
IRB.setup(nil)
|
9
|
+
irb_setup = true
|
10
|
+
end
|
5
11
|
irb = IRB::Irb.new IRB::WorkSpace.new(binding)
|
6
12
|
IRB.conf[:MAIN_CONTEXT] = irb.context
|
7
13
|
trap("SIGINT") { irb.signal_handle }
|
data/lib/binding.repl/rc.rb
CHANGED
@@ -1,18 +1,24 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
module Binding.repl::RC
|
2
|
+
module_function
|
3
|
+
def home_rc
|
4
|
+
File.join ENV["HOME"], ".binding.repl.rc"
|
5
|
+
end
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
def safe_load
|
8
|
+
if File.readable?(home_rc)
|
9
|
+
blob = File.read(home_rc)
|
10
|
+
rc = JSON.parse File.read(home_rc)
|
11
|
+
Binding.repl.auto_load_order = rc["auto_load_order"]
|
12
|
+
end
|
13
|
+
rescue StandardError => e
|
14
|
+
warn "binding.repl: '#{home_rc}' read failed (#{e.class}): #{e.message}"
|
10
15
|
end
|
11
16
|
end
|
12
17
|
|
13
|
-
if
|
14
|
-
|
18
|
+
if ENV["BINDING_REPL_ORDER"].nil? && ENV["BINDING_REPL_RC"] != "0"
|
19
|
+
require "json"
|
20
|
+
Binding.repl::RC.safe_load
|
15
21
|
end
|
16
|
-
if
|
17
|
-
Binding.repl.auto_load_order =
|
22
|
+
if ENV.has_key?("BINDING_REPL_ORDER")
|
23
|
+
Binding.repl.auto_load_order = ENV["BINDING_REPL_ORDER"].split /[:,]/
|
18
24
|
end
|
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.7.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-
|
12
|
+
date: 2013-10-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
segments:
|
87
87
|
- 0
|
88
|
-
hash:
|
88
|
+
hash: -334178767323369465
|
89
89
|
requirements: []
|
90
90
|
rubyforge_project:
|
91
91
|
rubygems_version: 1.8.23
|