rib 1.2.3 → 1.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c1a6d608c225a5dc61d4a9b58f6de671d17b7b0
4
- data.tar.gz: 07430433a3cee05dd733726a1ef07522a09f585f
3
+ metadata.gz: e72a119f6305e6c1e85579ae3e1b22564b6b5b56
4
+ data.tar.gz: 71f3bedf29f8cf9ae94a3fe9cfcf7317d0ef617c
5
5
  SHA512:
6
- metadata.gz: 1783b25cca7c85a1b79db3581568111ef077bf9e631037d1a0dbf8faeafb0d1514c8c35cdea6e95bdebc4d5e7847a151c101de426449d0555aa62cb158ea9600
7
- data.tar.gz: 9fbca213d0d22a3dd45d5a16a9b60c6e26cac2c971ee5fd09aa8983fabf7b43486f445183507272989484e43a1aa53dc957e115e58d8d1a547a8164972e8397c
6
+ metadata.gz: e5733937ed0bbb20cf9372a68e8fb937c1570d9a734e68e5137175237145ccc7f149bf7a3b9fcd5874aa37a3dd3c957a0487567ef6ee9161af88017dce160693
7
+ data.tar.gz: 31e66ea9bd8c01276b6c8b4a08e3321af27f47ff64f36295f5a85f52777a4ae47aa9194a61e79de96dd6a09aa22bea7706da4b73ae3d51c35f38ba5659f45372
data/.travis.yml CHANGED
@@ -4,7 +4,7 @@ script: 'ruby -r bundler/setup -S rake test'
4
4
  rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
- - 2.1.0
7
+ - ruby
8
8
  - rbx
9
9
  - jruby
10
10
 
data/CHANGES.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # CHANGES
2
2
 
3
+ ## Rib 1.2.4 -- 2014-03-13
4
+
5
+ * Fixed a regression introduced in 1.2.0. Now `rib all -e 'p 123'` should
6
+ work properly. Previously -e is ignored after rib apps.
7
+ * Fixed a long standing Windows issue, where `rib all` did not work because
8
+ there's no `which` on Windows. Now we fall back to `where`.
9
+ * Warn on removing main method on `TOPLEVEL_BINDING`. Not sure if this
10
+ would happen, but at least we could have a warning.
11
+
3
12
  ## Rib 1.2.3 -- 2014-02-08
4
13
 
5
14
  * [extra/paging] Properly disable paging if less or ENV['PAGER'] is not
data/lib/rib/runner.rb CHANGED
@@ -66,15 +66,14 @@ module Rib::Runner
66
66
 
67
67
  def run argv=ARGV
68
68
  (@running_commands ||= []) << Rib.config[:name]
69
- unused, e = parse(argv)
69
+ unused = parse(argv)
70
70
  # if it's running a Rib command, the loop would be inside Rib itself
71
71
  # so here we only parse args for the command
72
72
  return if @running_commands.pop != 'rib'
73
- # by comming to this line, it means now we're running Rib main loop,
73
+ # by coming to this line, it means now we're running Rib main loop,
74
74
  # not any other Rib command
75
75
  Rib.warn("Unused arguments: #{unused.inspect}") unless unused.empty?
76
76
  require 'rib/core' if Rib.config.delete(:mimic_irb)
77
- Rib.shell.eval_binding.eval(e, __FILE__, __LINE__)
78
77
  loop
79
78
  end
80
79
 
@@ -97,11 +96,12 @@ module Rib::Runner
97
96
  end
98
97
 
99
98
  def parse argv
100
- unused, e = [], ''
99
+ unused = []
101
100
  until argv.empty?
102
101
  case arg = argv.shift
103
102
  when /^-e=?(.+)?/, /^--eval=?(.+)?/
104
- e = $1 || argv.shift || ''
103
+ Rib.shell.eval_binding.eval(
104
+ $1 || argv.shift || '', __FILE__, __LINE__)
105
105
 
106
106
  when /^-d/, '--debug'
107
107
  $DEBUG = true
@@ -141,7 +141,7 @@ module Rib::Runner
141
141
  unused << arg
142
142
  end
143
143
  end
144
- [unused, e]
144
+ unused
145
145
  end
146
146
 
147
147
  def parse_next argv, arg
@@ -165,15 +165,21 @@ module Rib::Runner
165
165
 
166
166
  def load_command command
167
167
  bin = "rib-#{command}"
168
- path = `which #{bin}`.strip
168
+ path = which_bin(bin)
169
169
  if path == ''
170
170
  Rib.warn(
171
171
  "Can't find #{bin} in $PATH. Please make sure it is installed,",
172
- "or is there any typo? You can try this to install it:\n" ,
172
+ "or is there any typo? You can try this to install it:\n" ,
173
173
  " gem install #{bin}")
174
174
  else
175
175
  Rib.config[:name] = bin
176
176
  load(path)
177
177
  end
178
178
  end
179
+
180
+ def which_bin bin # handle windows here
181
+ `which #{bin}`.strip
182
+ rescue Errno::ENOENT # probably a windows platform, try where
183
+ `where #{bin}`.lines.first.strip
184
+ end
179
185
  end
data/lib/rib/shell.rb CHANGED
@@ -69,11 +69,14 @@ class Rib::Shell
69
69
  # Avoid namespace pollution from rubygems bin stub.
70
70
  # To be specific, version and str.
71
71
  def new_private_binding
72
- TOPLEVEL_BINDING.eval <<-RUBY
73
- def main; binding; end # anyway to define <main> method?
74
- ret = main
75
- Object.send(:remove_method, 'main') # never pollute anything
76
- ret
77
- RUBY
72
+ TOPLEVEL_BINDING.instance_eval do
73
+ singleton_class.module_eval do
74
+ Rib.warn("Removing existing main...") if method_defined?(:main)
75
+ def main; binding; end # any way to define <main> method?
76
+ end
77
+ ret = main
78
+ singleton_class.send(:remove_method, 'main') # never pollute anything
79
+ ret
80
+ end
78
81
  end
79
82
  end
data/lib/rib/test.rb CHANGED
@@ -77,6 +77,10 @@ module Kernel
77
77
  end
78
78
  end
79
79
 
80
+ def main
81
+ 'rib'
82
+ end
83
+
80
84
  Rib::Blackhole = Object.new
81
85
  b = Rib::Blackhole.singleton_class
82
86
  b.instance_methods(true).each{ |m|
data/lib/rib/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rib
3
- VERSION = '1.2.3'
3
+ VERSION = '1.2.4'
4
4
  end
data/rib.gemspec CHANGED
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rib 1.2.3 ruby lib
2
+ # stub: rib 1.2.4 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rib"
6
- s.version = "1.2.3"
6
+ s.version = "1.2.4"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib"]
10
10
  s.authors = ["Lin Jen-Shin (godfat)"]
11
- s.date = "2014-02-08"
11
+ s.date = "2014-03-13"
12
12
  s.description = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell\n\nRib is based on the design of [ripl][] and the work of [ripl-rc][], some of\nthe features are also inspired by [pry][]. The aim of Rib is to be fully\nfeatured and yet very easy to opt-out or opt-in other features. It shall\nbe simple, lightweight and modular so that everyone could customize Rib.\n\n[ripl]: https://github.com/cldwalker/ripl\n[ripl-rc]: https://github.com/godfat/ripl-rc\n[pry]: https://github.com/pry/pry"
13
13
  s.email = ["godfat (XD) godfat.org"]
14
14
  s.executables = [
data/test/test_runner.rb CHANGED
@@ -32,4 +32,23 @@ describe Rib::Runner do
32
32
  output
33
33
  Rib::Runner.run(%w[-e]).should.eq @shell
34
34
  end
35
+
36
+ def verify_app_e argv
37
+ input('a')
38
+ output('1')
39
+ conf = {:name => 'rib'}
40
+ min = 'rib-min'
41
+ mock(Rib::Runner).which_bin(min){ min }
42
+ mock(Rib::Runner).load(min){ Rib::Runner.run(argv) }
43
+ stub(Rib).config{ conf }
44
+ Rib::Runner.run(argv).should.eq @shell
45
+ end
46
+
47
+ should 'min -e' do
48
+ verify_app_e(%w[min -ea=1])
49
+ end
50
+
51
+ should '-e min' do
52
+ verify_app_e(%w[-ea=1 min])
53
+ end
35
54
  end
data/test/test_shell.rb CHANGED
@@ -7,40 +7,44 @@ describe Rib::Shell do
7
7
 
8
8
  before do
9
9
  Rib.disable_plugins
10
- @shell = Rib::Shell.new
10
+ @shell = nil
11
+ end
12
+
13
+ def shell
14
+ @shell ||= Rib::Shell.new
11
15
  end
12
16
 
13
17
  describe '#loop' do
14
18
  def input str
15
- mock(@shell).get_input{str}
16
- @shell.loop
19
+ mock(shell).get_input{str}
20
+ shell.loop
17
21
  true.should.eq true
18
22
  end
19
23
  should 'exit' do input('exit' ) end
20
24
  should 'also exit' do input(' exit') end
21
- should 'ctrl+d' do mock(@shell).puts{} ; input(nil) end
22
- should ':q' do @shell.config[:exit] << ':q'; input(':q') end
23
- should '\q' do @shell.config[:exit] << '\q'; input('\q') end
25
+ should 'ctrl+d' do mock(shell).puts{} ; input(nil) end
26
+ should ':q' do shell.config[:exit] << ':q'; input(':q') end
27
+ should '\q' do shell.config[:exit] << '\q'; input('\q') end
24
28
  end
25
29
 
26
30
  describe '#loop_once' do
27
31
  def input str=nil
28
32
  if block_given?
29
- mock(@shell).get_input{ yield }
33
+ mock(shell).get_input{ yield }
30
34
  else
31
- mock(@shell).get_input{ str }
35
+ mock(shell).get_input{ str }
32
36
  end
33
- @shell.loop_once
37
+ shell.loop_once
34
38
  true.should.eq true
35
39
  end
36
40
 
37
41
  should 'handles ctrl+c' do
38
- mock(@shell).handle_interrupt{}
42
+ mock(shell).handle_interrupt{}
39
43
  input{ raise Interrupt }
40
44
  end
41
45
 
42
46
  should 'prints result' do
43
- mock(@shell).puts('=> "mm"'){}
47
+ mock(shell).puts('=> "mm"'){}
44
48
  input('"m" * 2')
45
49
  end
46
50
 
@@ -55,44 +59,56 @@ describe Rib::Shell do
55
59
  end
56
60
 
57
61
  should 'print error from eval' do
58
- mock(@shell).puts(match(/RuntimeError/)){}
62
+ mock(shell).puts(match(/RuntimeError/)){}
59
63
  input('raise "blah"')
60
64
  end
61
65
  end
62
66
 
63
67
  describe '#prompt' do
64
68
  should 'be changeable' do
65
- @shell.config[:prompt] = '> '
66
- @shell.prompt.should.eq '> '
69
+ shell.config[:prompt] = '> '
70
+ shell.prompt.should.eq '> '
67
71
  end
68
72
  end
69
73
 
70
74
  describe '#eval_input' do
71
75
  before do
72
- @line = @shell.config[:line]
76
+ @line = shell.config[:line]
73
77
  end
74
78
 
75
79
  should 'line' do
76
- @shell.eval_input('10 ** 2')
77
- @shell.config[:line].should.eq @line + 1
80
+ shell.eval_input('10 ** 2')
81
+ shell.config[:line].should.eq @line + 1
78
82
  end
79
83
 
80
84
  should 'print error and increments line' do
81
- result, err = @shell.eval_input('{')
85
+ result, err = shell.eval_input('{')
82
86
  result.should.eq nil
83
87
  err.should.kind_of?(SyntaxError)
84
- @shell.config[:line].should.eq @line + 1
88
+ shell.config[:line].should.eq @line + 1
85
89
  end
86
90
  end
87
91
 
88
92
  should 'call after_loop even if in_loop raises' do
89
- mock(@shell).loop_once{ raise 'boom' }
93
+ mock(shell).loop_once{ raise 'boom' }
90
94
  mock(Rib).warn(is_a(String)){}
91
- mock(@shell).after_loop{}
92
- lambda{@shell.loop}.should.raise(RuntimeError)
95
+ mock(shell).after_loop{}
96
+ lambda{shell.loop}.should.raise(RuntimeError)
93
97
  end
94
98
 
95
99
  should 'have empty binding' do
96
- @shell.eval_input('local_variables').first.should.empty
100
+ shell.eval_input('local_variables').first.should.empty
101
+ end
102
+
103
+ should 'not pollute main' do
104
+ shell.eval_input('main').first.should.eq 'rib'
105
+ end
106
+
107
+ should 'warn on removing main' do
108
+ TOPLEVEL_BINDING.singleton_class.module_eval do
109
+ def main; end
110
+ end
111
+ mock(Rib).warn(is_a(String)){}
112
+ shell.eval_input('main').first.should.eq 'rib'
97
113
  end
98
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lin Jen-Shin (godfat)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-08 00:00:00.000000000 Z
11
+ date: 2014-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |-
14
14
  Ruby-Interactive-ruBy -- Yet another interactive Ruby shell