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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9efd8499161c382b7cac61e1e4f7e8e255e5a41c
4
- data.tar.gz: 5500700763ba3b2c6528001dcafffdafdc3b0595
3
+ metadata.gz: efdbef0970558803105b9fd7dded3ffdf38fb120
4
+ data.tar.gz: ff8b0424aeba9a3b5cc299a97a66a553e8ed9735
5
5
  SHA512:
6
- metadata.gz: d2249eb630d7d069bd6163d00d2305c54c75d4d8c76793b205750d41625afd664c99ee346fb4e0232b6371953a33780e273004a33df4ebfe86b971f3e4a289c2
7
- data.tar.gz: 08acad9f98824bed9f95d1732be4cbfd09aee7061d03c70883c850f4abc49340f5da7f872da130798a5dac2e7cdfa38ca661c1d137523df7f9ed1e166ec63823
6
+ metadata.gz: f31c9e90899e97cc0834b3cf2ca36c9ebdbe3aa36f16e681388d9ff68ed3bb3b42c1961728f83518398504ba7c2fadeae081a3d44cd7c03b15fd2c4c31176f38
7
+ data.tar.gz: 6fb64450c68878cecbeee80d12af3f3224fbc854c0d5030b919948a8822f6d0262e3d4e46711caf9c476578d4ad78751f3128d8ad42047ae8cc93ff1a3bc8080
@@ -0,0 +1,3 @@
1
+ ---
2
+ BUNDLE_PATH: ".gems"
3
+ BUNDLE_DISABLE_SHARED_GEMS: '1'
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ pkg/
3
+ .gems/
4
+ *.md~
5
+ *.rb~
6
+ *.rb#
@@ -0,0 +1,12 @@
1
+ install: bundle install
2
+ script: ruby -S rake
3
+
4
+ rvm:
5
+ - 1.9.3
6
+ - 2.1.3
7
+ - ruby-head
8
+ - jruby
9
+ - rbx-2
10
+
11
+ notifications:
12
+ email: true
@@ -0,0 +1,9 @@
1
+ == v3.0.0
2
+ * Remove Binding.repl
3
+ * Remove bin/binding.repl
4
+ * Remove BindingRepl::Runner
5
+ * Remove BindingRepl::ExitValue#success?
6
+ * Remove BindingRepl::ExitValue.unknown
7
+ * Remove BindingRepl::ENV
8
+ * Remove support for $auto shell var
9
+
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+ group :test do
4
+ gem 'rspec-core'
5
+ gem 'rspec-mocks'
6
+ gem 'minitest', require: ['minitest', 'minitest/unit']
7
+ end
@@ -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.
@@ -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.
@@ -0,0 +1,8 @@
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 = false
7
+ end
8
+ task :default => :test
@@ -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
@@ -0,0 +1,2 @@
1
+ require_relative '../lib/binding.repl'
2
+ binding.repl.ir
@@ -0,0 +1,3 @@
1
+ require_relative '../lib/binding.repl'
2
+ binding.repl.irb
3
+
@@ -0,0 +1,2 @@
1
+ require_relative '../lib/binding.repl'
2
+ binding.repl.pry
@@ -0,0 +1,2 @@
1
+ require_relative '../lib/binding.repl'
2
+ binding.repl.rib
@@ -0,0 +1,2 @@
1
+ require_relative '../lib/binding.repl'
2
+ binding.repl.ripl
@@ -1,14 +1,39 @@
1
1
  class BindingRepl
2
- LOOKUP = {}
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
- def self.auto_order=(list)
7
- @auto_order = list
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
- def self.auto_order
11
- @auto_order or BindingRepl::ENV.auto_order or DEFAULT_AUTO_ORDER
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,pry,rib,ripl}` become a no-op.
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
- # @param [Symbol] console
45
- # the name of a console. available as `binding.repl.<console>`.
69
+ # @param [Binding] binding
70
+ # a Binding object.
46
71
  #
47
- # @param [Proc] initializer
48
- # a Proc that is called on the very first call of `binding.repl.<console>`.
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
- @lookup = LOOKUP
77
+ @auto = BindingRepl.auto.dup
69
78
  end
70
79
 
71
80
  #
72
- # iterates through BindingRepl.auto_order and starts the first available console.
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
- # raises a LoadError when no consoles in BindingRepl.auto_order can be loaded
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} when the repl has exited.
87
+ # returns an instance of {BindingRepl::ExitValue}.
83
88
  #
84
89
  def auto
85
- consoles = BindingRepl.auto_order
86
- value = run_any_console(consoles)
87
- if consoles.empty?
88
- raise LoadError, "no consoles available to load. BindingRepl.auto_order is empty"
89
- elsif value.nil?
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
- private
98
- def die(console)
99
- raise LoadError, "failed to require '#{console}'"
100
- end
101
-
102
- def run_any_console(consoles)
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
- def run_console(console, options = {})
111
- console = console.to_s
112
- if BindingRepl.disabled?
113
- value = BindingRepl::ExitValue.disabled_value
114
- else
115
- initializer, runner = @lookup[console]
116
- initializer.call
117
- @lookup[console] = [@lookup.default.at(0), runner]
118
- value = runner.call @binding, options
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
- rescue LoadError
121
- value = BindingRepl::ExitValue.load_error_value
122
- ensure
123
- return BindingRepl::ExitValue.new(value)
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
- require_relative "binding.repl/core_ext/binding"
127
- require_relative "binding.repl/env"
128
- require_relative "binding.repl/exit_value"
129
- require_relative "binding.repl/version"
130
- require_relative "binding.repl/repls/pry"
131
- require_relative "binding.repl/repls/irb"
132
- require_relative "binding.repl/repls/ripl"
133
- require_relative "binding.repl/repls/rib"
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,8 +1,4 @@
1
1
  class Binding
2
- def self.repl
3
- BindingRepl
4
- end
5
-
6
2
  def repl
7
3
  BindingRepl.new(self)
8
4
  end
@@ -0,0 +1,7 @@
1
+ initializer = lambda do |name|
2
+ require(name) unless defined?(Ir)
3
+ end
4
+ runner = lambda do |binding, options|
5
+ Ir::Tty.new options.merge(binding: binding)
6
+ end
7
+ BindingRepl['ir'] = [initializer, runner]
@@ -1,11 +1,10 @@
1
- initializer = lambda do
2
- require "irb"
3
- IRB.setup(nil)
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
- irb = IRB::Irb.new IRB::WorkSpace.new(binding)
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.add :irb, initializer, runner
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 "pry"
3
- end
4
- runner = lambda do |binding, options|
5
- binding.pry(options)
6
- end
7
- BindingRepl.add :pry, initializer, runner
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
- require "rib"
3
- require "rib/more/anchor"
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 binding, options
8
+ Rib.anchor(binding, options)
7
9
  end
8
- BindingRepl.add :rib, initializer, runner
10
+ BindingRepl['rib'] = [initializer, runner]
11
+
@@ -1,7 +1,7 @@
1
- initializer = lambda do
2
- require "ripl"
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.add :ripl, initializer, runner
7
+ BindingRepl['ripl'] = [initializer, runner]
@@ -1,6 +1,3 @@
1
1
  class BindingRepl
2
- VERSION = "1.0.4.1"
3
- def self.version
4
- VERSION
5
- end
2
+ VERSION = '3.0.0'
6
3
  end
@@ -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
@@ -0,0 +1,5 @@
1
+ require 'bundler/setup'
2
+ Bundler.require :default, :test
3
+ require_relative 'support/mock'
4
+ require_relative 'support/repls'
5
+ Minitest.autorun
@@ -0,0 +1,15 @@
1
+ module BindingRepl::Mock
2
+ include RSpec::Mocks::ExampleMethods
3
+
4
+ def setup
5
+ RSpec::Mocks.setup
6
+ super
7
+ end
8
+
9
+ def teardown
10
+ RSpec::Mocks.verify
11
+ ensure
12
+ RSpec::Mocks.teardown
13
+ super
14
+ end
15
+ end
@@ -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: 1.0.4.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Public Domain
7
+ - rpag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-24 00:00:00.000000000 Z
11
+ date: 2014-10-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: binding.repl is `binding.pry` but for every ruby repl.
13
+ description:
14
14
  email:
15
- - robert@flowof.info
15
+ - rpag@singletonclass.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - LEGAL.txt
21
- - doc/disableatruntime.md
22
- - doc/exit_values.md
23
- - doc/runtimeoptions.md
24
- - doc/shellvariables.md
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/core_ext/binding.rb
27
- - lib/binding.repl/env.rb
28
- - lib/binding.repl/exit_value.rb
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
- homepage: https://github.com/robgleeson/binding.repl
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
- - Public Domain
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: 1.9.2
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.repl is `binding.pry` but for every ruby repl.
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/>
@@ -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
- ```
@@ -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
- ```
@@ -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
- ```
@@ -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
@@ -1,10 +0,0 @@
1
- module BindingRepl::ENV
2
- @env = ::ENV
3
- DELIMITER_REGEXP = /[:,]/
4
-
5
- def auto_order
6
- list = @env['auto_order'].to_s.split(DELIMITER_REGEXP)
7
- list.empty? ? nil : list
8
- end
9
- module_function :auto_order
10
- end
@@ -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