rib 1.5.1 → 1.5.2

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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/CHANGES.md +32 -0
  4. data/README.md +5 -4
  5. data/TODO.md +2 -0
  6. data/lib/rib.rb +1 -1
  7. data/lib/rib/api.rb +29 -8
  8. data/lib/rib/app/auto.rb +2 -3
  9. data/lib/rib/app/rack.rb +2 -3
  10. data/lib/rib/app/rails.rb +2 -3
  11. data/lib/rib/core/completion.rb +6 -13
  12. data/lib/rib/core/history.rb +3 -3
  13. data/lib/rib/core/last_value.rb +3 -3
  14. data/lib/rib/core/multiline.rb +3 -3
  15. data/lib/rib/core/readline.rb +3 -3
  16. data/lib/rib/core/squeeze_history.rb +3 -3
  17. data/lib/rib/core/strip_backtrace.rb +3 -3
  18. data/lib/rib/extra/autoindent.rb +3 -3
  19. data/lib/rib/extra/hirb.rb +3 -3
  20. data/lib/rib/extra/paging.rb +3 -3
  21. data/lib/rib/more/anchor.rb +13 -4
  22. data/lib/rib/more/beep.rb +4 -4
  23. data/lib/rib/more/bottomup_backtrace.rb +3 -3
  24. data/lib/rib/more/caller.rb +3 -3
  25. data/lib/rib/more/color.rb +11 -6
  26. data/lib/rib/more/edit.rb +3 -3
  27. data/lib/rib/more/multiline_history.rb +3 -3
  28. data/lib/rib/more/multiline_history_file.rb +3 -3
  29. data/lib/rib/plugin.rb +15 -4
  30. data/lib/rib/runner.rb +4 -3
  31. data/lib/rib/shell.rb +19 -6
  32. data/lib/rib/test.rb +25 -14
  33. data/lib/rib/test/history.rb +25 -0
  34. data/lib/rib/test/multiline.rb +8 -16
  35. data/lib/rib/version.rb +1 -1
  36. data/rib.gemspec +7 -6
  37. data/task/README.md +5 -5
  38. data/task/gemgem.rb +6 -1
  39. data/test/core/test_completion.rb +13 -6
  40. data/test/core/test_history.rb +42 -52
  41. data/test/core/test_last_value.rb +22 -23
  42. data/test/core/test_readline.rb +7 -14
  43. data/test/core/test_squeeze_history.rb +29 -36
  44. data/test/extra/test_autoindent.rb +8 -3
  45. data/test/more/test_anchor.rb +85 -0
  46. data/test/more/test_beep.rb +1 -1
  47. data/test/more/test_color.rb +16 -0
  48. data/test/more/test_multiline_history.rb +12 -7
  49. data/test/test_api.rb +39 -3
  50. data/test/test_plugin.rb +25 -13
  51. data/test/test_runner.rb +12 -10
  52. data/test/test_shell.rb +72 -23
  53. metadata +6 -5
  54. data/test/extra/test_anchor.rb +0 -18
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::Beep
5
- extend Rib::Plugin
4
+ module Rib; module Beep
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
@@ -10,7 +10,7 @@ module Rib::Beep
10
10
  def before_loop
11
11
  super
12
12
  return self if Beep.disabled?
13
- beep if (Time.now - config[:started_at]) > beep_threshold
13
+ beep if started_at && (Time.now - started_at) > beep_threshold
14
14
  Beep.disable
15
15
  self
16
16
  end
@@ -23,4 +23,4 @@ module Rib::Beep
23
23
  def beep_threshold
24
24
  config[:beep_threshold] ||= 5
25
25
  end
26
- end
26
+ end; end
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::BottomupBacktrace
5
- extend Rib::Plugin
4
+ module Rib; module BottomupBacktrace
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
@@ -16,4 +16,4 @@ module Rib::BottomupBacktrace
16
16
  def format_backtrace backtrace
17
17
  super(backtrace).reverse
18
18
  end
19
- end
19
+ end; end
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::Caller
5
- extend Rib::Plugin
4
+ module Rib; module Caller
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  module Imp
@@ -34,4 +34,4 @@ module Rib::Caller
34
34
  end
35
35
 
36
36
  Rib.extend(Imp)
37
- end
37
+ end; end
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::Color
5
- extend Rib::Plugin
4
+ module Rib; module Color
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
@@ -14,7 +14,7 @@ module Rib::Color
14
14
 
15
15
  def format_result result
16
16
  return super if Color.disabled?
17
- config[:result_prompt] + format_color(result)
17
+ "#{result_prompt}#{format_color(result)}"
18
18
  end
19
19
 
20
20
  def get_error err
@@ -23,6 +23,11 @@ module Rib::Color
23
23
  [format_color(err, message), format_backtrace(backtrace)]
24
24
  end
25
25
 
26
+ def warn message
27
+ return super if Color.disabled?
28
+ super(red{message})
29
+ end
30
+
26
31
  # --------------- Plugin API ---------------
27
32
 
28
33
  def colors
@@ -39,7 +44,7 @@ module Rib::Color
39
44
  Object => :yellow }
40
45
  end
41
46
 
42
- def format_color result, display=result.inspect
47
+ def format_color result, display=inspect_result(result)
43
48
  case result
44
49
  when String ; send(colors[String ]){ display }
45
50
  when Numeric; send(colors[Numeric]){ display }
@@ -66,7 +71,7 @@ module Rib::Color
66
71
  else ; if color = find_color(colors, result)
67
72
  send(color){ display }
68
73
  else
69
- send(colors[Object ]){ display }
74
+ send(colors[Object]){ display }
70
75
  end
71
76
  end
72
77
  end
@@ -110,7 +115,7 @@ module Rib::Color
110
115
  def cyan █ color(36, &block); end
111
116
  def white █ color(37, &block); end
112
117
  def reset █ color( 0, &block); end
113
- end
118
+ end; end
114
119
 
115
120
  begin
116
121
  require 'win32console' if defined?(Gem) && Gem.win_platform?
@@ -2,8 +2,8 @@
2
2
  require 'rib'
3
3
  require 'tempfile'
4
4
 
5
- module Rib::Edit
6
- extend Rib::Plugin
5
+ module Rib; module Edit
6
+ extend Plugin
7
7
  Shell.use(self)
8
8
 
9
9
  module Imp
@@ -35,4 +35,4 @@ module Rib::Edit
35
35
  end
36
36
 
37
37
  Rib.extend(Imp)
38
- end
38
+ end; end
@@ -2,8 +2,8 @@
2
2
  require 'rib/core/history' # dependency
3
3
  require 'rib/core/multiline' # dependency
4
4
 
5
- module Rib::MultilineHistory
6
- extend Rib::Plugin
5
+ module Rib; module MultilineHistory
6
+ extend Plugin
7
7
  Shell.use(self)
8
8
 
9
9
  # --------------- Rib API ---------------
@@ -45,4 +45,4 @@ module Rib::MultilineHistory
45
45
  def multiline_trash
46
46
  @multiline_trash ||= 0
47
47
  end
48
- end
48
+ end; end
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib/more/multiline_history'
3
3
 
4
- module Rib::MultilineHistoryFile
5
- extend Rib::Plugin
4
+ module Rib; module MultilineHistoryFile
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
@@ -46,4 +46,4 @@ module Rib::MultilineHistoryFile
46
46
  def multiline_history_file_token
47
47
  config[:multiline_history_file_token] ||= ' '
48
48
  end
49
- end
49
+ end; end
@@ -1,6 +1,5 @@
1
1
 
2
- module Rib; end
3
- module Rib::Plugin
2
+ module Rib; module Plugin
4
3
  attr_accessor :disabled
5
4
 
6
5
  def enable
@@ -25,8 +24,20 @@ module Rib::Plugin
25
24
  !!disabled
26
25
  end
27
26
 
27
+ # Backward compatibility
28
+ def const_missing mod
29
+ if Rib.const_defined?(mod)
30
+ Rib.warn("Using #{mod} is deprecated, please change to Rib::#{mod}",
31
+ "This compatibility layer would be removed in Rib 1.6+",
32
+ "Called: #{caller.first}")
33
+ Rib.const_get(mod)
34
+ else
35
+ super
36
+ end
37
+ end
38
+
28
39
  def self.extended mod
29
- mod.send(:include, Rib)
40
+ return unless mod.name
30
41
 
31
42
  snake_name = mod.name.sub(/(\w+::)+?(\w+)$/, '\2').
32
43
  gsub(/([A-Z][a-z]*)/, '\\1_').downcase[0..-2]
@@ -47,4 +58,4 @@ module Rib::Plugin
47
58
 
48
59
  Rib.singleton_class.module_eval(code, __FILE__, __LINE__)
49
60
  end
50
- end
61
+ end; end
@@ -1,7 +1,7 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::Runner
4
+ module Rib; module Runner
5
5
  module_function
6
6
  def options
7
7
  @options ||=
@@ -60,7 +60,8 @@ module Rib::Runner
60
60
 
61
61
  # Extract the text below __END__ in the bin file as the description
62
62
  def command_descriptions_find path
63
- File.read(path) =~ /Gem\.bin_path\(['"](.+)['"], ['"](.+)['"],/
63
+ # FIXME: Can we do better? This is not reliable
64
+ File.read(path) =~ /Gem\.activate_bin_path\(['"](.+)['"], ['"](.+)['"],/
64
65
  (File.read(Gem.bin_path($1, $2))[/\n__END__\n(.+)$/m, 1] || '').strip
65
66
  end
66
67
 
@@ -185,4 +186,4 @@ module Rib::Runner
185
186
  rescue Errno::ENOENT # probably a windows platform, try where
186
187
  `where #{bin}`.lines.first.strip
187
188
  end
188
- end
189
+ end; end
@@ -2,8 +2,8 @@
2
2
  require 'rib/plugin'
3
3
  require 'rib/api'
4
4
 
5
- class Rib::Shell
6
- include Rib::API
5
+ module Rib; class Shell
6
+ include API
7
7
  trap('INT'){ raise Interrupt }
8
8
 
9
9
  def self.use mod
@@ -41,27 +41,40 @@ class Rib::Shell
41
41
  :prompt => '>> ',
42
42
  :exit => [nil],
43
43
  :line => 1 }.merge(config)
44
- @running = false
44
+ stop
45
45
  end
46
46
 
47
47
  # Loops shell until user exits
48
48
  def loop
49
49
  before_loop
50
- @running = true
50
+ start
51
51
  in_loop
52
+ stop
52
53
  self
53
54
  rescue Exception => e
54
55
  Rib.warn("Error while running loop:\n #{format_error(e)}")
55
56
  raise
56
57
  ensure
57
- @running = false
58
+
58
59
  after_loop
59
60
  end
60
61
 
62
+ def start
63
+ @running = true
64
+ end
65
+
66
+ def stop
67
+ @running = false
68
+ end
69
+
61
70
  def running?
62
71
  !!@running
63
72
  end
64
73
 
74
+ def warnings
75
+ @warnings ||= []
76
+ end
77
+
65
78
  protected
66
79
  attr_writer :config
67
80
 
@@ -79,4 +92,4 @@ class Rib::Shell
79
92
  ret
80
93
  RUBY
81
94
  end
82
- end
95
+ end; end
@@ -7,18 +7,40 @@ Pork::Suite.include(Muack::API)
7
7
  require 'rib'
8
8
 
9
9
  copy :rib do
10
+ before do
11
+ Rib.disable_plugins
12
+ end
13
+
10
14
  after do
11
15
  Muack.verify
12
16
  end
13
17
 
18
+ def shell opts={}
19
+ @shell ||= new_shell(opts)
20
+ end
21
+
14
22
  def new_shell opts={}
15
- shell = Rib::Shell.new(
16
- {:binding => Object.new.instance_eval{binding}}.merge(opts)
17
- )
23
+ shell = Rib::Shell.new(opts)
18
24
  yield(shell) if block_given?
19
25
  shell.before_loop
20
26
  end
21
27
 
28
+ def stub_output
29
+ stub(shell).print(is_a(String)){}
30
+ stub(shell).puts(is_a(String)){}
31
+ end
32
+
33
+ def readline?
34
+ Rib.constants.map(&:to_s).include?('Readline') &&
35
+ Rib::Readline.enabled?
36
+ end
37
+
38
+ def stub_readline meth=:stub
39
+ send(meth, ::Readline).readline(is_a(String), true) do
40
+ (::Readline::HISTORY << str.chomp).last
41
+ end
42
+ end
43
+
22
44
  singleton_class.module_eval do
23
45
  def test_for *plugins, &block
24
46
  require 'rib/all' # exhaustive tests
@@ -68,17 +90,6 @@ copy :rib do
68
90
  test_level3(rest[1..-1], block)
69
91
  end
70
92
  end
71
-
72
- def readline?
73
- Rib.constants.map(&:to_s).include?('Readline') &&
74
- Rib::Readline.enabled?
75
- end
76
-
77
- def stub_readline
78
- stub(::Readline).readline(is_a(String), true){
79
- (::Readline::HISTORY << str.chomp).last
80
- }
81
- end
82
93
  end
83
94
 
84
95
  def main
@@ -0,0 +1,25 @@
1
+
2
+ require 'tempfile'
3
+
4
+ copy :setup_history do
5
+ before do
6
+ if readline?
7
+ ::Readline::HISTORY.clear
8
+ stub_readline
9
+ end
10
+
11
+ shell(:history_file => history_file)
12
+ end
13
+
14
+ after do
15
+ tempfile.unlink if @tempfile
16
+ end
17
+
18
+ def tempfile
19
+ @tempfile ||= Tempfile.new('rib')
20
+ end
21
+
22
+ def history_file
23
+ tempfile.path
24
+ end
25
+ end
@@ -1,16 +1,8 @@
1
1
 
2
2
  copy :setup_multiline do
3
- def setup_shell
4
- @shell = new_shell
5
- stub(@shell).print{}.with_any_args
6
- stub(@shell).puts{} .with_any_args
7
- end
8
-
9
3
  def setup_input str
10
4
  if readline?
11
- mock(::Readline).readline(is_a(String), true){
12
- (::Readline::HISTORY << str.chomp)[-1]
13
- }
5
+ stub_readline(:mock)
14
6
  else
15
7
  mock($stdin).gets{ str.chomp }
16
8
  end
@@ -18,17 +10,17 @@ copy :setup_multiline do
18
10
 
19
11
  def input str
20
12
  setup_input(str)
21
- mock(@shell).throw(:rib_multiline)
13
+ mock(shell).throw(:rib_multiline)
22
14
  end
23
15
 
24
16
  def input_done str, err=nil
25
17
  setup_input(str)
26
18
  if err
27
- mock(@shell).print_eval_error(is_a(err)){}
19
+ mock(shell).print_eval_error(is_a(err)){}
28
20
  else
29
- mock(@shell).print_result(is_a(Object)){}
21
+ mock(shell).print_result(is_a(Object)){}
30
22
  end
31
- @shell.loop_once
23
+ shell.loop_once
32
24
  ok
33
25
  end
34
26
 
@@ -36,7 +28,7 @@ copy :setup_multiline do
36
28
  lines = str.split("\n")
37
29
  lines[0...-1].each{ |line|
38
30
  input(line)
39
- @shell.loop_once
31
+ shell.loop_once
40
32
  }
41
33
  input_done(lines.last, err)
42
34
  end
@@ -44,11 +36,11 @@ end
44
36
 
45
37
  copy :multiline do
46
38
  before do
47
- setup_shell
39
+ stub_output
48
40
  end
49
41
 
50
42
  would 'work with no prompt' do
51
- @shell.config[:prompt] = ''
43
+ shell.config[:prompt] = ''
52
44
  check <<-RUBY
53
45
  def f
54
46
  0
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rib
3
- VERSION = '1.5.1'
3
+ VERSION = '1.5.2'
4
4
  end
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: rib 1.5.1 ruby lib
2
+ # stub: rib 1.5.2 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "rib".freeze
6
- s.version = "1.5.1"
6
+ s.version = "1.5.2"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Lin Jen-Shin (godfat)".freeze]
11
- s.date = "2017-03-09"
11
+ s.date = "2017-05-01"
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".freeze
13
13
  s.email = ["godfat (XD) godfat.org".freeze]
14
14
  s.executables = [
@@ -67,6 +67,7 @@ Gem::Specification.new do |s|
67
67
  "lib/rib/runner.rb".freeze,
68
68
  "lib/rib/shell.rb".freeze,
69
69
  "lib/rib/test.rb".freeze,
70
+ "lib/rib/test/history.rb".freeze,
70
71
  "lib/rib/test/multiline.rb".freeze,
71
72
  "lib/rib/version.rb".freeze,
72
73
  "rib.gemspec".freeze,
@@ -79,8 +80,8 @@ Gem::Specification.new do |s|
79
80
  "test/core/test_readline.rb".freeze,
80
81
  "test/core/test_squeeze_history.rb".freeze,
81
82
  "test/core/test_strip_backtrace.rb".freeze,
82
- "test/extra/test_anchor.rb".freeze,
83
83
  "test/extra/test_autoindent.rb".freeze,
84
+ "test/more/test_anchor.rb".freeze,
84
85
  "test/more/test_beep.rb".freeze,
85
86
  "test/more/test_caller.rb".freeze,
86
87
  "test/more/test_color.rb".freeze,
@@ -90,7 +91,7 @@ Gem::Specification.new do |s|
90
91
  "test/test_runner.rb".freeze,
91
92
  "test/test_shell.rb".freeze]
92
93
  s.homepage = "https://github.com/godfat/rib".freeze
93
- s.licenses = ["Apache License 2.0".freeze]
94
+ s.licenses = ["Apache-2.0".freeze]
94
95
  s.rubygems_version = "2.6.10".freeze
95
96
  s.summary = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell".freeze
96
97
  s.test_files = [
@@ -101,8 +102,8 @@ Gem::Specification.new do |s|
101
102
  "test/core/test_readline.rb".freeze,
102
103
  "test/core/test_squeeze_history.rb".freeze,
103
104
  "test/core/test_strip_backtrace.rb".freeze,
104
- "test/extra/test_anchor.rb".freeze,
105
105
  "test/extra/test_autoindent.rb".freeze,
106
+ "test/more/test_anchor.rb".freeze,
106
107
  "test/more/test_beep.rb".freeze,
107
108
  "test/more/test_caller.rb".freeze,
108
109
  "test/more/test_color.rb".freeze,