binding.repl 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/.binding.repl.rc ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "auto_load_order": ["pry", "ripl", "irb"]
3
+ }
data/.pryrc CHANGED
@@ -1 +1,2 @@
1
+ ENV["BINDING_REPL_RC"] = "0"
1
2
  require "./lib/binding.repl"
data/ChangeLog.txt CHANGED
@@ -1,3 +1,15 @@
1
+ == v0.5.0
2
+ - disable {$HOME,$CWD}/.binding.repl.rc loading
3
+ set ENV["BINDING_REPL_RC"] = 0 to disable load.
4
+
5
+ == v0.4.1
6
+ - read {$HOME,$CWD}/.binding.repl.rc as JSON
7
+ safer.
8
+
9
+ == v0.4.0
10
+ - read {$HOME,$CWD}/.binding.ripl.rc on load
11
+ see README for docs.
12
+
1
13
  == v0.3.0
2
14
  - add Binding.repl.add
3
15
  add a ruby console to binding.repl
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
  |:----------------|:--------------------------------------------------
3
3
  | Homepage | https://github.com/robgleeson/binding.repl
4
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)
5
6
  | CI | [![Build Status](https://travis-ci.org/robgleeson/ichannel.binding.repl.png)](https://travis-ci.org/robgleeson/binding.repl)
6
7
  | Author | Robert Gleeson
7
8
 
@@ -32,7 +33,7 @@ __EXAMPLES__
32
33
  class BlogsController < ApplicationController
33
34
  def show
34
35
  @blog = Blog.find(params[:id])
35
- # invoke pry,irb, or ripl in the context of the 'show' method.
36
+ # starts pry, irb, or ripl in the context of 'BlogsController#show'.
36
37
  binding.repl.{pry,irb,ripl}
37
38
  end
38
39
  end
@@ -74,6 +75,39 @@ class Foo
74
75
  end
75
76
  ```
76
77
 
78
+ _WORKING WITH TEAMS_
79
+
80
+ people working in teams might have different choices for what ruby
81
+ console they like to use and __binding.repl__ tries to accomondate by
82
+ reading a `.binding.repl.rc` file from $HOME or the current working
83
+ directory. It's a JSON file with a single key-value pair.
84
+
85
+ amy prefers IRB, so her `$HOME/.binding.repl.rc` would look like this:
86
+ ```javascript
87
+ {
88
+ "auto_load_order": ["irb", "pry", "ripl"]
89
+ }
90
+ ```
91
+
92
+ rob prefers pry, so his `$HOME/.binding.repl.rc` would look like this:
93
+ ```ruby
94
+ {
95
+ "auto_load_order": ["irb", "pry", "ripl"]
96
+ }
97
+ ```
98
+
99
+ when either rob or amy wants to start their favorite ruby console
100
+ they can use `binding.repl.auto`:
101
+
102
+ ```ruby
103
+ # lib/foo.rb
104
+ class Foo
105
+ # starts "irb" in the context of Foo for amy.
106
+ # starts "pry" in the context of Foo for rob.
107
+ binding.repl.auto
108
+ end
109
+ ```
110
+
77
111
  _RIPL & IRB_
78
112
 
79
113
  I have only used Ripl once(to write this library) and I don't use IRB
@@ -107,7 +141,7 @@ __CREDIT__
107
141
  Rest of the Pry team(!!):
108
142
 
109
143
  - [cirwin](https://github.com/conradirwin), Conrad Irwin.
110
- - [ryanf](https://github.com/ryanf), Ryan Fitzgerald.
144
+ - [ryanf](https://github.com/rf-), Ryan Fitzgerald.
111
145
  - [rking](https://github.com/rking), "rking", on adventures outside programming now.
112
146
 
113
147
  __LICENSE__
data/lib/binding.repl.rb CHANGED
@@ -18,14 +18,14 @@ class BindingRepl
18
18
  end
19
19
 
20
20
  def self.version
21
- "0.3.0"
21
+ "0.5.0"
22
22
  end
23
23
 
24
24
  def self.add(console, predicate, runner)
25
25
  LOOKUP[console] = [predicate, runner]
26
26
  define_method(console) do |options = {}|
27
27
  exit_value = invoke_console(console, options)
28
- error?(exit_value) ? fail!(console) : exit_value
28
+ invoke_failed?(exit_value) ? fail!(console) : exit_value
29
29
  end
30
30
  end
31
31
 
@@ -46,7 +46,7 @@ class BindingRepl
46
46
  load_order = Binding.repl.auto_load_order
47
47
  load_order.each do |console|
48
48
  exit_value = invoke_console(console.to_sym, {})
49
- return exit_value unless error?(exit_value)
49
+ return exit_value unless invoke_failed?(exit_value)
50
50
  end
51
51
  raise LoadError, "failed to load consoles: #{load_order.join(", ")}", []
52
52
  end
@@ -56,7 +56,7 @@ private
56
56
  raise LoadError, "the console '#{console}' could not be loaded. is #{console} installed?", []
57
57
  end
58
58
 
59
- def error?(exit_value)
59
+ def invoke_failed?(exit_value)
60
60
  exit_value.to_s.start_with? "binding.repl"
61
61
  end
62
62
 
@@ -88,3 +88,7 @@ end
88
88
  require_relative "binding.repl/pry"
89
89
  require_relative "binding.repl/irb"
90
90
  require_relative "binding.repl/ripl"
91
+
92
+ if ENV["BINDING_REPL_RC"].to_i != 0
93
+ require_relative "binding.repl/rc"
94
+ end
@@ -2,6 +2,6 @@ predicate = lambda do
2
2
  defined?(Pry)
3
3
  end
4
4
  runner = lambda do |binding, options|
5
- binding.public_send :pry, options
5
+ binding.pry(options)
6
6
  end
7
7
  Binding.repl.add :pry, predicate, runner
@@ -0,0 +1,17 @@
1
+ require "json"
2
+ home_rc = File.join ENV["HOME"], ".binding.repl.rc"
3
+ local_rc = File.join Dir.getwd, ".binding.repl.rc"
4
+
5
+ if File.exists?(home_rc)
6
+ json = File.read(home_rc)
7
+ end
8
+ if !File.exists?(home_rc) && File.exists?(local_rc)
9
+ json = File.read(local_rc)
10
+ end
11
+
12
+ if local_rc || home_rc
13
+ options = JSON.parse(json) rescue nil
14
+ end
15
+ if options
16
+ Binding.repl.auto_load_order = options["auto_load_order"]
17
+ 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.3.0
4
+ version: 0.5.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-28 00:00:00.000000000 Z
12
+ date: 2013-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -50,6 +50,7 @@ executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
52
  files:
53
+ - .binding.repl.rc
53
54
  - .gitignore
54
55
  - .pryrc
55
56
  - ChangeLog.txt
@@ -61,6 +62,7 @@ files:
61
62
  - lib/binding.repl.rb
62
63
  - lib/binding.repl/irb.rb
63
64
  - lib/binding.repl/pry.rb
65
+ - lib/binding.repl/rc.rb
64
66
  - lib/binding.repl/ripl.rb
65
67
  homepage: https://github.com/robgleeson/binding.repl
66
68
  licenses:
@@ -83,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
85
  version: '0'
84
86
  segments:
85
87
  - 0
86
- hash: 2298799895627227771
88
+ hash: 184924604236581946
87
89
  requirements: []
88
90
  rubyforge_project:
89
91
  rubygems_version: 1.8.23