binding.repl 0.8.0 → 0.9.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8c8ee86e2adcf420c60b05111ce45b43a00343b9
4
+ data.tar.gz: 117c6da32749481c1cd5436b5f5c43100904c2c7
5
+ SHA512:
6
+ metadata.gz: 42a9a9d209908ea84a870c9a655d3227ab98725302f3fa799a37bd193cf980cfdac8f2391220b0f66df47be772a80aebe4802915b35ca7560154b4b3f06023fc
7
+ data.tar.gz: 993a7b4835312e617d3c9554e3217384fded40b6c048bf63a331d0f55fa20a52ad4cb283000c3081dcdd7badcde57961019a08caa4f3135eb01cac1a95416a20
data/.binding.repl.rc CHANGED
@@ -1,3 +1,6 @@
1
- {
2
- "auto_load_order": ["pry", "ripl", "irb"]
3
- }
1
+ #
2
+ # a sample of what $HOME/.binding.repl.rc might look like.
3
+ # the default lookup order for `binding.repl.auto` can be defined in this file.
4
+ #
5
+ [auto]
6
+ order = ["irb", "rib", "pry", "ripl"]
data/.gitignore CHANGED
@@ -7,7 +7,6 @@ Gemfile.lock
7
7
  InstalledFiles
8
8
  _yardoc
9
9
  coverage
10
- doc/
11
10
  lib/bundler/man
12
11
  pkg
13
12
  rdoc
data/.pryrc CHANGED
@@ -1,2 +1,3 @@
1
1
  ENV["BINDING_REPL_RC"] = "0"
2
- require "./lib/binding.repl"
2
+ require "bundler/setup"
3
+ require "binding.repl"
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - rbx
9
+ - jruby-19mode
10
+
11
+ notifications:
12
+ email: true
data/ChangeLog.txt CHANGED
@@ -1,20 +1,73 @@
1
+ == v0.9.0
2
+ - read $HOME/.binding.repl.rc as TOML instead of JSON
3
+ TOML is easy to read and write when compared with JSON. I don't think
4
+ humans like writing JSON too much :) you can get up to speed with TOML
5
+ at https://github.com/mojombo/toml.
6
+ closes GH #12.
7
+
8
+ - rename Binding.repl.auto_load_order as Binding.repl.auto_order.
9
+ closes GH #14.
10
+
11
+ - rename shell environment variable BINDING_REPL_ORDER as auto_order
12
+ less keys to press, no SHIFT key needed!
13
+ a little background on why I decided to try lowercase.
14
+ http://pubs.opengroup.org/onlinepubs/7908799/xbd/envvar.html
15
+ closes GH #15.
16
+
17
+ - rename shell environment variable BINDING_REPL_RC as disable_rc.
18
+ ditto.
19
+ closes GH #15.
20
+
21
+ - 1.9.2 support
22
+ use of `private_constant` broke binding.repl support on 1.9.2
23
+ decided to not try and workaround it.
24
+ BindingRepl::LOOKUP is no longer a private constant.
25
+
26
+ - define the default lookup order for `binding.repl.auto`.
27
+ defined by default as ["pry", "ripl", "rib", "irb"].
28
+
29
+ - relicense binding.repl under the public domain
30
+ interesting idea. see http://unlicense.org
31
+
32
+ - rewrite all the documentation in doc/
33
+ the documentation that covers shell environment variables, the rc file, runtime options
34
+ and how to enable or disable binding.repl at runtime has been rewritten and polished for
35
+ what I think is much better docs!
36
+
37
+ - add BindingRepl::ENV
38
+ a module on top of shell environment variables binding.repl understands.
39
+
40
+ - rename BindingRepl::RC as BindingRepl::RCFile.
41
+ most of the module was rewritten and cleaned up.
42
+
43
+ - raise a LoadError from `binding.repl.auto` when no consoles are available.
44
+ when BindingRepl.auto_order has been assigned an empty array and then `binding.repl.auto` is
45
+ called a LoadError will be raised. the old behavior was to return nil.
46
+
47
+ - raise a LoadError with a backtrace
48
+ if a console cannot be loaded a LoadError is raised with a backtrace.
49
+ before, there was no backtrace (not helpful).
50
+
51
+ - with 100% more tests.
52
+ binding.repl has never had a test suite. at every release I would do a manual test
53
+ process that is prone to error. I can't repeat my actions as well as a computer. in this release
54
+ binding.repl has a testcase for every class or module available.
55
+
56
+ the test suite is builton FakeFS(when testing the rcfile) and a mocking library(rspec-mocks) when
57
+ testing the execution of ruby consoles.
58
+
1
59
  == v0.8.0
2
60
  - add "rib" as a supported console.
3
61
  "rib" is inspired by ripl, the ripl-rc project, and by some of
4
62
  the ideas from the pry project.
5
63
 
6
- be sure to check it out if you're curious:
64
+ if you're curious:
7
65
  * https://github.com/godfat/rib
8
66
 
9
- 'binding.repl.rib' to try it out!
10
-
11
- - internals shakeup
12
- when a console is added to binding.repl it also defines an
13
- initializer that should be run for the very first time.
14
-
15
- binding.repl takes care of the initializer not being run again,
16
- but the initializer is expected to do whatever it needs to make
17
- the console available for use.
67
+ - add auto management of initializers
68
+ when a console is added to binding.repl it also must define an
69
+ initializer that is run the very first time a console is invoked.
70
+ binding.repl takes care of the initializer not being run again.
18
71
 
19
72
  see lib/binding.repl/console/*.rb for examples.
20
73
 
data/Gemfile CHANGED
@@ -1,8 +1,22 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
- group :repls do
4
+ group :development do
5
+ gem "rake"
6
+ end
7
+
8
+ group :test do
9
+ gem "rspec-mocks"
10
+ end
11
+
12
+ group :test, :repls do
5
13
  gem 'ripl'
6
14
  gem 'pry'
7
15
  gem 'rib'
16
+ gem "fakefs", require: "fakefs/safe"
8
17
  end
18
+
19
+ platform :rbx do
20
+ gem "rubysl"
21
+ gem "rubysl-test-unit"
22
+ end
data/README.md CHANGED
@@ -1,31 +1,27 @@
1
1
  | Project | binding.repl
2
2
  |:----------------|:--------------------------------------------------
3
- | Homepage | https://github.com/robgleeson/binding.repl
4
- | Documentation | http://rubydoc.info/github/robgleeson/binding.repl
5
- | Code Metrics | [![Code Climate](https://codeclimate.com/github/robgleeson/binding.repl.png)](https://codeclimate.com/github/robgleeson/binding.repl)
6
- | CI | [![Build Status](https://travis-ci.org/robgleeson/ichannel.binding.repl.png)](https://travis-ci.org/robgleeson/binding.repl)
7
- | Author | Robert Gleeson
3
+ | homepage | https://github.com/robgleeson/binding.repl
4
+ | build | [![Build Status](https://travis-ci.org/robgleeson/binding.repl.png)](https://travis-ci.org/robgleeson/binding.repl)
8
5
 
9
6
  __DESCRIPTION__
10
7
 
11
8
  __binding.repl__ can start a number of different ruby consoles at runtime.
12
9
  IRB, ripl, rib, and pry(of course!) can be invoked at runtime in any context
13
- that an instance of `Binding` closes over.
10
+ that an instance of `Binding` closes over. I owe credit to John Mair([banisterfiend](https://github.com/banister)),
11
+ the creator of pry, for seeing the potential in a console that can be started at
12
+ runtime and bound to the context of a `Binding` easily.
14
13
 
15
- I owe all credit to John Mair([banisterfiend](https://github.com/banister)),
16
- the creator of Pry, for seeing the potential in a console that can be
17
- started at runtime and bound to the context of a `Binding`. I don't
18
- think a single ruby console has put as much emphasize on a console
19
- that be invoked at runtime as Pry has.
14
+ the interface to invoke pry at runtime has become known in a lot of circles and
15
+ I thought it'd be cool to offer the same feature to other REPLs.
20
16
 
21
- the interface to invoke Pry at runtime is very accessible and easy to
22
- use but if you look at other ruby console implementations you might find
23
- the eval() of code is the same. It happens through `Binding#eval` which
24
- closes over a context(maybe the context is "Foo", a class, or an
25
- instance of "Foo").
17
+ __FEATURES__
26
18
 
27
- __binding.repl__ provides the same `binding.pry` interface to all ruby
28
- consoles (if I missed one, open an issue or send an e-note :)).
19
+ - `binding.pry` for all ruby consoles
20
+ - start the consoles IRB, Pry, Ripl, or Rib at runtime
21
+ - option to auto discover and start the first available console
22
+ - enable or disable at runtime(a la Pry)
23
+ - configurable via shell environment variables and an optional RC file in `$HOME`.
24
+ - easily extended to support new consoles.
29
25
 
30
26
  __EXAMPLES__
31
27
 
@@ -35,136 +31,64 @@ _Rails_
35
31
  class BlogsController < ApplicationController
36
32
  def show
37
33
  @blog = Blog.find(params[:id])
38
- binding.repl.{pry,irb,ripl,rib,auto}
34
+ binding.repl.{pry,irb,ripl,rib}
39
35
  end
40
36
  end
41
37
  ```
42
38
 
43
39
  _Auto discovery_
44
40
 
45
- ```ruby
46
- class Bar
47
- # auto discover and start the first available console.
48
- # default order is: ripl, pry, rib, or irb.
49
- binding.repl.auto
50
-
51
- # change default load order
52
- Binding.repl.auto_load_order = %w(pry ripl irb rib)
53
-
54
- # remove "irb" & "rib" from auto discovery
55
- Binding.repl.auto_load_order -= ["irb", "rib"]
56
- end
57
- ```
58
-
59
- _Enable/disable at runtime_
60
-
61
- ```ruby
62
- class Baz
63
- # invoke irb
64
- binding.repl.irb
65
- Binding.repl.disable!
66
-
67
- # no-op, returns :'binding.repl.disabled' and continues execution.
68
- binding.repl.irb
69
- binding.repl.ripl
70
-
71
- # invoke pry
72
- Binding.repl.enable!
73
- binding.repl.pry
74
- end
75
- ```
76
-
77
- __NOTES__
78
-
79
- _CONFIGURATION_
80
-
81
- ripl, rib, and pry can be customized by passing a set of key-value pairs but
82
- IRB isn't as straight forward to configure and I haven't implemented
83
- any customization options for it yet.
84
-
85
- ripl can be invoked with options that are forwarded to `Ripl.start(…)`:
86
-
87
- ```ruby
88
- class Foo
89
- binding.repl.ripl riplrc: false
90
- end
91
- ```
92
-
93
- pry can be configured in the same way. options are forwarded to `Pry.start(…)`:
41
+ the first available console can be loaded with `binding.repl.auto`. the default order
42
+ is defined `["pry", "ripl", "rib", "irb"]` but it can be changed at runtime, through
43
+ an RC file, and with shell environment variables.
94
44
 
95
45
  ```ruby
96
46
  class Foo
97
- binding.repl.pry quiet: true
98
- end
99
- ```
100
-
101
- rib is a little less well known ruby console that binding.repl
102
- supports since v0.8.0. I don't know much about the options it accepts,
103
- but it does accept some. please check out [its github page](https://github.com/godfat/rib)
104
- if you're curious.
47
+ # auto discover and start the first available console.
48
+ binding.repl.auto
105
49
 
106
- ```ruby
107
- class Foo
108
- binding.repl.rib({})
50
+ # change default load order of auto (pry first, etc..)
51
+ Binding.repl.auto_order = ["pry", "ripl", "irb"]
109
52
  end
110
53
  ```
111
54
 
112
- _WORKING WITH TEAMS_
55
+ __DOCS__
113
56
 
114
- people working in teams might have different choices for what ruby
115
- console they like to use and __binding.repl__ tries to accomondate by
116
- reading a `.binding.repl.rc` file from $HOME or by setting a shell
117
- environment variable. `binding.repl.rc` is a simple JSON file.
57
+ - RCFILE <br>
58
+ configure the default order of `binding.repl.auto` with an RC file.
118
59
 
119
- let's say rob & amy are working on some code together. amy prefers
120
- ripl, so her `$HOME/.binding.repl.rc` would look like this:
121
- ```javascript
122
- {
123
- "auto_load_order": ["ripl", "irb"]
124
- }
125
- ```
60
+ see [doc/rcfile.md](https://github.com/robgleeson/binding.repl/blob/master/doc/rcfile.md)
126
61
 
127
- rob prefers pry, so his `$HOME/.binding.repl.rc` would look like this:
128
- ```ruby
129
- {
130
- "auto_load_order": ["pry", "irb"]
131
- }
132
- ```
62
+ - SHELL ENVIRONMENT VARIABLES <br>
63
+ temporarily disable the RC file or configure the default of order of `binding.repl.auto` with shell
64
+ envionment variables.
133
65
 
134
- when either rob or amy wants to start their favorite ruby console
135
- they can use `binding.repl.auto`:
66
+ see [doc/shellvariables.md](https://github.com/robgleeson/binding.repl/blob/master/doc/shellvariables.md)
136
67
 
137
- ```ruby
138
- class Foo
139
- # starts "irb" in the context of Foo for amy. fall back console is "irb".
140
- # starts "pry" in the context of Foo for rob. fall back console is "irb".
141
- binding.repl.auto
142
- end
143
- ```
144
-
145
- _SHELL ENVIRONMENT VARIABLES_
68
+ - RUNTIME OPTIONS <br>
69
+ ripl, rib, and pry can be configured at runtime by passing a set of
70
+ key-value pairs but IRB isn't as straight forward to configure and I
71
+ haven't implemented any customization options for it yet.
146
72
 
147
- binding.repl can be configured with a couple of shell environment variables.
73
+ see [doc/runtimeoptions.md](https://github.com/robgleeson/binding.repl/blob/master/doc/runtimeoptions.md)
148
74
 
149
- ```bash
150
- # disable trying to read $HOME/.binding.repl.rc
151
- export BINDING_REPL_RC=0
75
+ - ENABLE/DISABLE AT RUNTIME <br>
76
+ binding.repl can be enabled or disabled at runtime.
152
77
 
153
- # set the 'auto' load order
154
- # takes precendence over $HOME/.binding.repl.rc when set
155
- export BINDING_REPL_ORDER=pry,irb
156
- ```
78
+ see [doc/disableatruntime.md](https://github.com/robgleeson/binding.repl/blob/master/doc/disableatruntime.md)
157
79
 
158
- _DEPENDENCIES_
80
+ __DEPENDENCIES__
159
81
 
160
82
  binding.repl doesn't depend on anything. it's up to you to meet the
161
83
  dependencies(pry, irb, rib, and/or ripl). `binding.repl.{ripl,pry,rib,irb}`
162
84
  will try to load the appropiate console for you if it looks like it
163
85
  hasn't been loaded yet.
164
86
 
165
- __INSTALL__
87
+ __PLATFORM SUPPORT__
166
88
 
167
- ruby 1.9+ only.
89
+ should work on all 1.9+ ruby implementations. please open an issue if you find a bug!
90
+
91
+ __INSTALL__
168
92
 
169
93
  ```
170
94
  gem install binding.repl
@@ -186,7 +110,8 @@ Rest of the Pry team(!!):
186
110
 
187
111
  __LICENSE__
188
112
 
189
- MIT.
113
+ Public Domain. see UNLICENSE.txt.
114
+
190
115
 
191
116
  __CONTRIBUTING__
192
117
 
data/Rakefile CHANGED
@@ -1 +1,16 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.test_files = FileList["test/*_test.rb"]
6
+ t.verbose = true
7
+ end
8
+ task :default => :test
9
+
10
+ desc "run the examples in examples/*.rb"
11
+ task :examples do
12
+ Dir["examples/*.rb"].each do |example|
13
+ sh "ruby %s" % [example]
14
+ puts
15
+ end
16
+ end
data/UNLICENSE.txt ADDED
@@ -0,0 +1,24 @@
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. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
data/binding.repl.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # coding: utf-8
2
- require "./lib/binding.repl"
2
+ require "./lib/binding.repl/version"
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "binding.repl"
5
- spec.version = Binding.repl.version
5
+ spec.version = BindingRepl.version
6
6
  spec.authors = ["Robert Gleeson"]
7
7
  spec.email = ["rob@flowof.info"]
8
8
  spec.description = "binding.repl: binding.pry for all ruby consoles"
9
9
  spec.summary = spec.description
10
10
  spec.homepage = "https://github.com/robgleeson/binding.repl"
11
- spec.license = "MIT"
11
+ spec.license = "Public Domain"
12
12
 
13
13
  spec.files = `git ls-files`.split($/)
14
14
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -16,20 +16,18 @@ Gem::Specification.new do |spec|
16
16
  spec.require_paths = ["lib"]
17
17
  spec.required_ruby_version = ">= 1.9.2"
18
18
 
19
+ spec.add_runtime_dependency "toml", "~> 0.0.3"
19
20
  spec.add_development_dependency "bundler", "~> 1.3"
20
21
  spec.add_development_dependency "rake"
21
22
 
22
23
  spec.post_install_message = <<-INSTALL_MESSAGE
23
24
 
24
25
  ** binding.repl **
25
- Thanks for installing v#{Binding.repl.version}!
26
- Check out the README and ChangeLog to see what's new in this release.
27
-
28
- README.md
29
- https://github.com/robgleeson/binding.repl/blob/v#{Binding.repl.version}/README.md
26
+ Thanks for installing v#{BindingRepl.version}!
27
+ Check out ChangeLog.txt to read about what's changed.
30
28
 
31
29
  ChangeLog.txt
32
- https://github.com/robgleeson/binding.repl/blob/v#{Binding.repl.version}/ChangeLog.txt
30
+ https://github.com/robgleeson/binding.repl/blob/v#{BindingRepl.version}/ChangeLog.txt
33
31
 
34
32
  INSTALL_MESSAGE
35
33
  end
@@ -0,0 +1,20 @@
1
+ __ENABLE/DISABLE AT RUNTIME__
2
+
3
+ binding.repl can be enabled or disabled at runtime. by default, it is enabled.
4
+ to disable, you'd write something like:
5
+
6
+ ```ruby
7
+ class Foo
8
+ Binding.repl.disable!
9
+ binding.repl.irb # does nothing. execution continues.
10
+ end
11
+ ```
12
+
13
+ it can be re-enabled just as easily:
14
+
15
+ ```ruby
16
+ class Foo
17
+ Binding.repl.enable!
18
+ binding.repl.irb # opens an IRB session inside class 'Foo'
19
+ end
20
+ ```
data/doc/rcfile.md ADDED
@@ -0,0 +1,20 @@
1
+ __RCFILE__
2
+
3
+ binding.repl reads a configuration file from `$HOME/.binding.repl.rc`.
4
+ the configuration file is written in a human readable and writable
5
+ language called [toml](https://github.com/mojombo/toml).
6
+
7
+ at the moment the only configuration option is to define the order that
8
+ `binding.repl.auto` will use to look for ruby consoles. the example sets
9
+ up pry to be the first preference, then ripl, then rib, and finally irb.
10
+
11
+ ```toml
12
+ [auto]
13
+ order = ["pry", "ripl", "rib", "irb"]
14
+ ```
15
+
16
+ __DISABLE OR OVERRIDE__
17
+
18
+ the RC file is optional. if it doesn't exist that's cool.
19
+ it can be temporarily disabled and overriden by setting [shell environment variables](https://github.com/robgleeson/binding.repl/blob/master/doc/shellvariables.md)
20
+ when it does exist.
@@ -0,0 +1,42 @@
1
+ __RUNTIME OPTIONS__
2
+
3
+ __pry__
4
+
5
+ pry can be started with options that are forwarded to [Pry.start(…)](http://rubydoc.info/github/banister/pry/Pry#start-class_method) (API docs).
6
+
7
+ ```ruby
8
+ class Foo
9
+ binding.repl.pry quiet: true
10
+ end
11
+ ```
12
+
13
+ __ripl__
14
+
15
+ ripl can be started with options that are forwarded to `Ripl.start(…)`.
16
+ unfortunately, `Ripl.start(…)` has no API documentation.
17
+ check out [its github page](https://github.com/cldwalker/ripl) for more information.
18
+
19
+ ```ruby
20
+ class Foo
21
+ binding.repl.ripl riplrc: false
22
+ end
23
+ ```
24
+
25
+ __rib__
26
+
27
+ [rib](https://github.com/godfat/rib) is a little less well known ruby console that binding.repl
28
+ supports since v0.8.0. it can be configured to change the prompt and the prefix inserted before
29
+ a return value.
30
+
31
+ rib can be started with options that are forwarded to
32
+ [Rib.anchor(…)](http://rdoc.info/github/godfat/rib/Rib/Anchor/Imp#anchor-instance_method) (API docs).
33
+
34
+ ```ruby
35
+ class Foo
36
+ binding.repl.rib prompt: ">> ", result_prompt: "# => "
37
+ end
38
+ ```
39
+
40
+ __irb__
41
+
42
+ binding.repl doesn't implement any runtime options for IRB.
@@ -0,0 +1,21 @@
1
+ __SHELL ENVIRONMENT VARIABLES__
2
+
3
+ __$auto\_order__
4
+
5
+ binding.repl can start the first available console through `binding.repl.auto`. the lookup order
6
+ can be defined in an RC file or with an environment variable. the environment variable is simply
7
+ named `auto_order` and takes precendece over an RC file when defined. values can be separated by
8
+ a comma(`,`) or a colon(`:`).
9
+
10
+ example
11
+
12
+ $ auto_order=pry,irb ruby myscript.rb
13
+
14
+ __$disable\_rc__
15
+
16
+ the `disable_rc` environment variable can be set to '1' or 'true' to disable or abort the load
17
+ of `$HOME/.binding.repl.rc`.
18
+
19
+ example
20
+
21
+ $ disable_rc=1 ruby myscript.rb
data/lib/binding.repl.rb CHANGED
@@ -1,39 +1,58 @@
1
1
  class BindingRepl
2
- module BindingMixin
3
- def repl
4
- Binding.repl.new(self)
5
- end
6
- end
7
-
8
2
  LOOKUP = {}
9
3
  LOOKUP.default = [proc { true }, proc { :'binding.repl.unknown_console' }]
10
- private_constant :LOOKUP
4
+ singleton_class.class_eval { attr_accessor :auto_order }
11
5
 
12
6
  def self.name
13
7
  "binding.repl"
14
8
  end
15
9
 
16
- def self.inspect
10
+ def self.to_s
17
11
  name
18
12
  end
19
13
 
20
- def self.version
21
- "0.8.0"
22
- end
23
-
14
+ #
15
+ # returns when binding.repl is disabled.
16
+ #
17
+ # @return [Boolean]
18
+ #
24
19
  def self.disabled?
25
20
  @disabled
26
21
  end
27
22
 
23
+ #
24
+ # enable binding.repl (enabled by default)
25
+ #
26
+ # @return [true]
27
+ #
28
28
  def self.enable!
29
29
  @disabled = false
30
30
  !@disabled
31
31
  end
32
32
 
33
+ #
34
+ # disable binding.repl
35
+ # future calls to `binding.repl.{auto,pry,rib,ripl}` become a no-op.
36
+ #
37
+ # @return [true]
38
+ #
33
39
  def self.disable!
34
40
  @disabled = true
35
41
  end
36
42
 
43
+ #
44
+ # @param [Symbol] console
45
+ # the name of a console. available as `binding.repl.<console>`.
46
+ #
47
+ # @param [Proc] initializer
48
+ # a Proc that is called on the very first call of `binding.repl.<console>`.
49
+ #
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 [void]
55
+ #
37
56
  def self.add(console, initializer, runner)
38
57
  LOOKUP[console] = [initializer, runner]
39
58
  define_method(console) do |options = {}|
@@ -42,33 +61,27 @@ class BindingRepl
42
61
  end
43
62
  end
44
63
 
45
- def self.auto_load_order=(order)
46
- @auto_load_order = order
47
- end
48
-
49
- def self.auto_load_order
50
- @auto_load_order
51
- end
52
-
53
64
  def initialize(binding)
54
65
  @binding = binding
55
66
  @lookup = LOOKUP
56
67
  end
57
68
 
58
69
  def auto
59
- load_order, exit_value = Binding.repl.auto_load_order, nil
70
+ load_order, exit_value = Binding.repl.auto_order, nil
60
71
  load_order.each do |console|
61
72
  exit_value = invoke_console(console.to_sym, {})
62
73
  return exit_value unless invoke_failed?(exit_value)
63
74
  end
64
- if invoke_failed?(exit_value)
65
- raise LoadError, "failed to load consoles: #{load_order.join(", ")}", []
75
+ if load_order.empty?
76
+ raise LoadError, "no consoles found in Binding.repl.auto_order (empty)"
77
+ elsif invoke_failed?(exit_value)
78
+ raise LoadError, "no loadable consoles found (searched for #{load_order.join(', ')})"
66
79
  end
67
80
  end
68
81
 
69
82
  private
70
83
  def fail!(console)
71
- raise LoadError, "the console '#{console}' could not be loaded. is #{console} installed?", []
84
+ raise LoadError, "the console '#{console}' could not be loaded :("
72
85
  end
73
86
 
74
87
  def invoke_failed?(exit_value)
@@ -88,16 +101,14 @@ private
88
101
  :'binding.repl.load_error'
89
102
  end
90
103
  end
91
-
92
- klass = BindingRepl
93
- Object.send :remove_const, :BindingRepl
94
- Binding.class_eval do
95
- define_singleton_method(:repl) { klass }
96
- include klass::BindingMixin
97
- repl.auto_load_order = %w(ripl pry irb)
98
- end
104
+ require_relative "binding.repl/core_ext/binding"
105
+ require_relative "binding.repl/env"
106
+ require_relative "binding.repl/rcfile"
107
+ require_relative "binding.repl/version"
99
108
  require_relative "binding.repl/console/pry"
100
109
  require_relative "binding.repl/console/irb"
101
110
  require_relative "binding.repl/console/ripl"
102
111
  require_relative "binding.repl/console/rib"
103
- require_relative "binding.repl/rc"
112
+
113
+ BindingRepl::RCFile.load
114
+ BindingRepl.auto_order = BindingRepl::ENV.auto_order
@@ -2,7 +2,6 @@ initializer = lambda do
2
2
  require "irb"
3
3
  IRB.setup(nil)
4
4
  end
5
-
6
5
  runner = lambda do |binding, options|
7
6
  irb = IRB::Irb.new IRB::WorkSpace.new(binding)
8
7
  IRB.conf[:MAIN_CONTEXT] = irb.context
@@ -0,0 +1,9 @@
1
+ class Binding
2
+ def self.repl
3
+ BindingRepl
4
+ end
5
+
6
+ def repl
7
+ Binding.repl.new(self)
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module BindingRepl::ENV
2
+ @env = ::ENV
3
+ DEFAULT_AUTO_ORDER = ["pry", "ripl", "rib", "irb"]
4
+
5
+ module_function
6
+ def enable_rc_file?
7
+ @env['disable_rc'] != 'true' and @env['disable_rc'] != '1'
8
+ end
9
+
10
+ def disable_rc_file?
11
+ !enable_rc_file?
12
+ end
13
+
14
+ def auto_order
15
+ env_order = @env['auto_order'].to_s.split /[:,]/
16
+ env_order.empty? ? DEFAULT_AUTO_ORDER : env_order
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require "toml"
2
+ module BindingRepl::RCFile
3
+ module_function
4
+ def path
5
+ File.join ENV["HOME"], ".binding.repl.rc"
6
+ end
7
+
8
+ def enabled?
9
+ BindingRepl::ENV.enable_rc_file?
10
+ end
11
+
12
+ def load
13
+ return nil unless enabled? and File.readable?(path)
14
+ content = File.read(path)
15
+ parsed = TOML::Parser.new(content).parsed
16
+ Binding.repl.auto_order = parsed["auto"]["order"]
17
+ rescue StandardError => e
18
+ warn "binding.repl: '#{path}' read failed."
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ class BindingRepl
2
+ VERSION = "0.9.0".freeze
3
+
4
+ def self.version
5
+ VERSION
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ require_relative "setup"
2
+ class BindingReplAutoTest < Test::Unit::TestCase
3
+ include BindingRepl::Mock
4
+ def setup
5
+ @before = BindingRepl.auto_order
6
+ super
7
+ end
8
+
9
+ def teardown
10
+ BindingRepl.auto_order = @before
11
+ super
12
+ end
13
+
14
+ def test_pry_as_first_match_on_auto
15
+ BindingRepl.auto_order = ["pry", "irb"]
16
+ expect(Pry).to receive(:start).with(instance_of(Binding), {})
17
+ binding.repl.auto
18
+ end
19
+
20
+ def test_ripl_as_second_match_on_auto
21
+ BindingRepl.auto_order = ["blah", "ripl"]
22
+ expect(Ripl).to receive(:start).with(binding: instance_of(Binding))
23
+ binding.repl.auto
24
+ end
25
+
26
+ def test_no_matches_on_auto
27
+ BindingRepl.auto_order = []
28
+ e = assert_raise(LoadError) {binding.repl.auto}
29
+ assert_equal "no consoles found in Binding.repl.auto_order (empty)", e.message
30
+ end
31
+
32
+ def test_no_requireable_console_on_auto
33
+ BindingRepl.auto_order = ["ry", "burp", "orc"]
34
+ e = assert_raise(LoadError) {binding.repl.auto}
35
+ assert_equal "no loadable consoles found (searched for ry, burp, orc)", e.message
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ require_relative "setup"
2
+ class BindingReplEnvTest < Test::Unit::TestCase
3
+ def teardown
4
+ ENV.delete "disable_rc"
5
+ ENV.delete "auto_order"
6
+ end
7
+
8
+ def test_default_of_enable_rc_file?
9
+ assert_equal true, BindingRepl::ENV.enable_rc_file?
10
+ end
11
+
12
+ def test_disable_of_rc_file_with_true
13
+ ENV["disable_rc"] = 'true'
14
+ assert_equal false, BindingRepl::ENV.enable_rc_file?
15
+ end
16
+
17
+ def test_disable_of_rc_file_with_one
18
+ ENV["disable_rc"] = '1'
19
+ assert_equal false, BindingRepl::ENV.enable_rc_file?
20
+ end
21
+
22
+ def test_default_of_auto_order
23
+ assert_equal BindingRepl::ENV::DEFAULT_AUTO_ORDER, BindingRepl.auto_order
24
+ end
25
+
26
+ def test_auto_order_defined_by_shell
27
+ ENV["auto_order"] = 'irb,ripl'
28
+ assert_equal ["irb", "ripl"], BindingRepl::ENV.auto_order
29
+ end
30
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "setup"
2
+ require "irb"
3
+ class BindingReplIrbTest < Test::Unit::TestCase
4
+ include BindingRepl::Mock
5
+ def test_irb
6
+ expect_any_instance_of(::IRB::Irb).to receive(:eval_input)
7
+ binding.repl.irb
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "setup"
2
+ class BindingReplPryTest < Test::Unit::TestCase
3
+ include BindingRepl::Mock
4
+ def test_pry
5
+ expect(Pry).to receive(:start).with(instance_of(Binding), {})
6
+ binding.repl.pry
7
+ end
8
+
9
+ def test_pry_with_options
10
+ expect(Pry).to receive(:start).with(instance_of(Binding), {quiet: true})
11
+ binding.repl.pry quiet: true
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ require_relative "setup"
2
+ testcase = if defined?(Rubinius)
3
+ # skip Rubinius (breaks with FakeFS).
4
+ Object
5
+ else
6
+ Test::Unit::TestCase
7
+ end
8
+
9
+ class BindingReplRCFileTest < testcase
10
+ DIR = File.dirname BindingRepl::RCFile.path
11
+ FILENAME = File.basename BindingRepl::RCFile.path
12
+
13
+ def setup
14
+ FakeFS.activate!
15
+ dir = FakeFS::FileSystem.add DIR
16
+ file = FakeFS::FakeFile.new FILENAME, dir
17
+ file.content = <<-RCFILE
18
+ [auto]
19
+ order = ["fakerepl", "irb"]
20
+ RCFILE
21
+ dir[file.name] = file
22
+ end
23
+
24
+ def teardown
25
+ FakeFS.deactivate!
26
+ end
27
+
28
+ def test_auto_order_defined_by_rc_file
29
+ BindingRepl::RCFile.load
30
+ assert_equal ["fakerepl", "irb"], BindingRepl.auto_order
31
+ end
32
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "setup"
2
+ class BindingReplRibTest < Test::Unit::TestCase
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 < Test::Unit::TestCase
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
data/test/setup.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "bundler"
2
+ require "test/unit"
3
+ Bundler.require :default, :test
4
+ require_relative "support/binding.repl/mock"
@@ -0,0 +1,14 @@
1
+ module BindingRepl::Mock
2
+ include RSpec::Mocks::ExampleMethods
3
+
4
+ def setup
5
+ RSpec::Mocks.setup(Object)
6
+ RSpec::Mocks.setup(self)
7
+ end
8
+
9
+ def teardown
10
+ RSpec::Mocks.verify
11
+ ensure
12
+ RSpec::Mocks.teardown
13
+ end
14
+ end
metadata CHANGED
@@ -1,99 +1,136 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binding.repl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
5
- prerelease:
4
+ version: 0.9.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Robert Gleeson
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-13 00:00:00.000000000 Z
11
+ date: 2014-01-05 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: toml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.3
14
27
  - !ruby/object:Gem::Dependency
15
28
  name: bundler
16
29
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
30
  requirements:
19
- - - ~>
31
+ - - "~>"
20
32
  - !ruby/object:Gem::Version
21
33
  version: '1.3'
22
34
  type: :development
23
35
  prerelease: false
24
36
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
37
  requirements:
27
- - - ~>
38
+ - - "~>"
28
39
  - !ruby/object:Gem::Version
29
40
  version: '1.3'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rake
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - ">="
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - ">="
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
- description: ! 'binding.repl: binding.pry for all ruby consoles'
55
+ description: 'binding.repl: binding.pry for all ruby consoles'
47
56
  email:
48
57
  - rob@flowof.info
49
58
  executables: []
50
59
  extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
53
- - .binding.repl.rc
54
- - .gitignore
55
- - .pryrc
62
+ - ".binding.repl.rc"
63
+ - ".gitignore"
64
+ - ".pryrc"
65
+ - ".travis.yml"
56
66
  - ChangeLog.txt
57
67
  - Gemfile
58
- - LICENSE.txt
59
68
  - README.md
60
69
  - Rakefile
70
+ - UNLICENSE.txt
61
71
  - binding.repl.gemspec
72
+ - doc/disableatruntime.md
73
+ - doc/rcfile.md
74
+ - doc/runtimeoptions.md
75
+ - doc/shellvariables.md
62
76
  - lib/binding.repl.rb
63
77
  - lib/binding.repl/console/irb.rb
64
78
  - lib/binding.repl/console/pry.rb
65
79
  - lib/binding.repl/console/rib.rb
66
80
  - lib/binding.repl/console/ripl.rb
67
- - lib/binding.repl/rc.rb
81
+ - lib/binding.repl/core_ext/binding.rb
82
+ - lib/binding.repl/env.rb
83
+ - lib/binding.repl/rcfile.rb
84
+ - lib/binding.repl/version.rb
85
+ - test/binding_repl_auto_test.rb
86
+ - test/binding_repl_env_test.rb
87
+ - test/binding_repl_irb_test.rb
88
+ - test/binding_repl_pry_test.rb
89
+ - test/binding_repl_rcfile_test.rb
90
+ - test/binding_repl_rib_test.rb
91
+ - test/binding_repl_ripl_test.rb
92
+ - test/setup.rb
93
+ - test/support/binding.repl/mock.rb
68
94
  homepage: https://github.com/robgleeson/binding.repl
69
95
  licenses:
70
- - MIT
71
- post_install_message: ! "\n ** binding.repl **\n Thanks for installing v0.8.0!\n
72
- \ Check out the README and ChangeLog to see what's new in this release.\n\n README.md\n
73
- \ https://github.com/robgleeson/binding.repl/blob/v0.8.0/README.md\n\n ChangeLog.txt\n
74
- \ https://github.com/robgleeson/binding.repl/blob/v0.8.0/ChangeLog.txt\n\n"
96
+ - Public Domain
97
+ metadata: {}
98
+ post_install_message: |2+
99
+
100
+ ** binding.repl **
101
+ Thanks for installing v0.9.0!
102
+ Check out ChangeLog.txt to read about what's changed.
103
+
104
+ ChangeLog.txt
105
+ https://github.com/robgleeson/binding.repl/blob/v0.9.0/ChangeLog.txt
106
+
75
107
  rdoc_options: []
76
108
  require_paths:
77
109
  - lib
78
110
  required_ruby_version: !ruby/object:Gem::Requirement
79
- none: false
80
111
  requirements:
81
- - - ! '>='
112
+ - - ">="
82
113
  - !ruby/object:Gem::Version
83
114
  version: 1.9.2
84
115
  required_rubygems_version: !ruby/object:Gem::Requirement
85
- none: false
86
116
  requirements:
87
- - - ! '>='
117
+ - - ">="
88
118
  - !ruby/object:Gem::Version
89
119
  version: '0'
90
- segments:
91
- - 0
92
- hash: 4383143691404002571
93
120
  requirements: []
94
121
  rubyforge_project:
95
- rubygems_version: 1.8.23
122
+ rubygems_version: 2.2.0
96
123
  signing_key:
97
- specification_version: 3
98
- summary: ! 'binding.repl: binding.pry for all ruby consoles'
99
- test_files: []
124
+ specification_version: 4
125
+ summary: 'binding.repl: binding.pry for all ruby consoles'
126
+ test_files:
127
+ - test/binding_repl_auto_test.rb
128
+ - test/binding_repl_env_test.rb
129
+ - test/binding_repl_irb_test.rb
130
+ - test/binding_repl_pry_test.rb
131
+ - test/binding_repl_rcfile_test.rb
132
+ - test/binding_repl_rib_test.rb
133
+ - test/binding_repl_ripl_test.rb
134
+ - test/setup.rb
135
+ - test/support/binding.repl/mock.rb
136
+ has_rdoc:
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Robert Gleeson
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,24 +0,0 @@
1
- module Binding.repl::RC
2
- module_function
3
- def home_rc
4
- File.join ENV["HOME"], ".binding.repl.rc"
5
- end
6
-
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}"
15
- end
16
- end
17
-
18
- if ENV["BINDING_REPL_ORDER"].nil? && ENV["BINDING_REPL_RC"] != "0"
19
- require "json"
20
- Binding.repl::RC.safe_load
21
- end
22
- if ENV.has_key?("BINDING_REPL_ORDER")
23
- Binding.repl.auto_load_order = ENV["BINDING_REPL_ORDER"].split /[:,]/
24
- end