rib 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1c625bc0da2b14df1f4856299b5f5c44d79915a
4
- data.tar.gz: 30688e5296926f1e38a67c3695181c796a0bbb7d
3
+ metadata.gz: ddd655c34f6696f9ee88606efcf30acbd726ad54
4
+ data.tar.gz: 46ad8ec8b715f478c0677a1a49c0190473df42df
5
5
  SHA512:
6
- metadata.gz: 41a078427da34028fbbed7f377c9e906e5b6e2a8cc53c2f30d0ac7fa5c888667fc1ab0aa0ef2f5c6927306c35887a81db0b6ba50eabb6ef2af147d0d6b84797d
7
- data.tar.gz: 1c600c0587d555cf031130be807e46a29057ae99538e239f7b0d4ab5a23eaf1c9d169504fb928930f8296ff04fbad92126df705e8bd1928ec28336dae542469a
6
+ metadata.gz: ba6586bba0c20fb2cfdb1a731d67824a1f43f9fe1d240b7764ab8de50394e0c4c595799cad527cdd80ecc1201203c4f3acd286736aac2e87dda1c71659b6363e
7
+ data.tar.gz: '080e885ebd7e6a8e5be217e985ff5efa40631b4847a15b887aea158f43ef1b1a66d43b96538d36abb642f69537045f2704b71899b37eb43ffa2bfd005caff6ca'
@@ -12,7 +12,7 @@ matrix:
12
12
  include:
13
13
  - rvm: 2.2.5
14
14
  - rvm: 2.3.2
15
- - rvm: 2.4.0
15
+ - rvm: 2.4.1
16
16
  - rvm: jruby-9
17
17
  env: JRUBY_OPTS=--debug
18
18
  - rvm: rbx
data/CHANGES.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # CHANGES
2
2
 
3
+ ## Rib 1.5.2 -- 2017-05-01
4
+
5
+ * We now `require 'rib/version'` from the beginning, avoid loading error
6
+ under bundler.
7
+ * Introduced `API#started_at` which is `config[:started_at]` for accessing
8
+ when Rib started.
9
+ * Introduced `API#inspect_result` which would inspect the result. The default
10
+ behaviour would just inspect the result, but if the result is not a string,
11
+ emit a warning. https://github.com/godfat/rib/issues/14
12
+ * Now all warnings would be printed after the result was printed. This would
13
+ make it easier to spot warnings.
14
+ * [more/color] It would now paint warnings.
15
+ * [more/anchor] Introduced `Rib.stop_anchors` to stop all nested anchors.
16
+ https://github.com/godfat/rib/issues/13
17
+ * Fixed Rib app detection for newer RubyGems
18
+
19
+ ### Breaking changes
20
+
21
+ * Extending `Rib::Plugin` would no longer automatically also include `Rib`.
22
+ For compatibility concern, a `const_missing` is now defined in `Rib::Plugin`
23
+ so that using `Shell` would still refer to `Rib::Shell` for you, considering
24
+ that this might be a common pattern:
25
+
26
+ extend Rib::Plugin
27
+ Shell.use(self)
28
+
29
+ Note that this would be removed in the future, so please take this chance to
30
+ change it to:
31
+
32
+ extend Rib::Plugin
33
+ Rib::Shell.use(self)
34
+
3
35
  ## Rib 1.5.1 -- 2017-03-09
4
36
 
5
37
  * [more/beep] This plugin would beep via `print "\a"` when the application
data/README.md CHANGED
@@ -190,11 +190,11 @@ rib options:
190
190
  -h, --help Print this message
191
191
  -v, --version Print the version
192
192
  rib commands:
193
- min Run the minimum essence
194
- auto Run as Rails or Rack console (auto-detect)
195
193
  all Load all recommended plugins
196
- rails Run as Rails console
194
+ auto Run as Rails or Rack console (auto-detect)
195
+ min Run the minimum essence
197
196
  rack Run as Rack console
197
+ rails Run as Rails console
198
198
  ```
199
199
 
200
200
  #### Basic configuration
@@ -455,11 +455,12 @@ simple, simpler than rib-rails.
455
455
  * Lin Jen-Shin (@godfat)
456
456
  * Mr. Big Cat (@miaout17)
457
457
  * @bootleq
458
+ * @lulalala
458
459
  * @tka
459
460
 
460
461
  ## LICENSE:
461
462
 
462
- Apache License 2.0
463
+ Apache License 2.0 (Apache-2.0)
463
464
 
464
465
  Copyright (c) 2011-2017, Lin Jen-Shin (godfat)
465
466
 
data/TODO.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # TODO
2
2
 
3
+ * cleanup the tests. it's so messy right now
4
+
3
5
  * Runner tests
4
6
  * Documentation
5
7
  * Implement exception_spy
data/lib/rib.rb CHANGED
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib/shell'
3
+ require 'rib/version'
3
4
 
4
5
  module Rib
5
- autoload :VERSION, 'rib/version'
6
6
  Skip = Object.new
7
7
 
8
8
  module_function
@@ -1,6 +1,5 @@
1
1
 
2
- module Rib; end
3
- module Rib::API
2
+ module Rib; module API
4
3
  # Called before shell starts looping
5
4
  def before_loop
6
5
  self
@@ -23,18 +22,22 @@ module Rib::API
23
22
  def eval_binding ; config[:binding] ; end
24
23
  # The line number for next evaluation
25
24
  def line ; config[:line] ; end
25
+ # When the application loaded
26
+ def started_at ; config[:started_at] ; end
26
27
 
27
28
  # Main loop
28
29
  def in_loop
29
- input = catch(:rib_exit){ loop_once while true }
30
- puts if input == nil
30
+ input = catch(:rib_exit){ loop_once while running? }
31
+ puts if input == nil && running?
31
32
  end
32
33
 
33
34
  # Loop iteration: REPL
34
35
  def loop_once
35
36
  input, result, err = get_input, nil, nil
36
37
  throw(:rib_exit, input) if config[:exit].include?(input)
38
+
37
39
  result, err = eval_input(input)
40
+
38
41
  if err
39
42
  print_eval_error(err)
40
43
  elsif input.strip != '' && !equal_rib_skip(result)
@@ -42,6 +45,9 @@ module Rib::API
42
45
  else
43
46
  # print nothing for blank input or Rib::Skip
44
47
  end
48
+
49
+ flush_warnings
50
+
45
51
  [result, err]
46
52
  rescue Interrupt
47
53
  handle_interrupt
@@ -81,23 +87,34 @@ module Rib::API
81
87
  def print_result result
82
88
  puts(format_result(result))
83
89
  rescue StandardError, SyntaxError => e
84
- Rib.warn("Error while printing result:\n #{format_error(e)}")
90
+ warn("Error while printing result:\n #{format_error(e)}")
85
91
  end
86
92
 
87
93
  # Print evaluated error using #format_error
88
94
  def print_eval_error err
89
95
  puts(format_error(err))
90
96
  rescue StandardError, SyntaxError => e
91
- Rib.warn("Error while printing error:\n #{format_error(e)}")
97
+ warn("Error while printing error:\n #{format_error(e)}")
92
98
  end
93
99
 
94
100
  def puts str
95
101
  super
96
102
  end
97
103
 
104
+ def warn message
105
+ warnings << message
106
+ end
107
+
98
108
  # Format result using #result_prompt
99
109
  def format_result result
100
- result_prompt + result.inspect
110
+ "#{result_prompt}#{inspect_result(result)}"
111
+ end
112
+
113
+ def inspect_result result
114
+ string = result.inspect
115
+ warn("#{result.class}#inspect is not returning a string") unless
116
+ string.kind_of?(String)
117
+ string
101
118
  end
102
119
 
103
120
  # Format error raised in #loop_eval with #get_error
@@ -123,4 +140,8 @@ module Rib::API
123
140
  rescue
124
141
  # do nothing, it cannot respond to == correctly, it can't be Rib::Skip
125
142
  end
126
- end
143
+
144
+ def flush_warnings
145
+ Rib.warn(warnings.shift) until warnings.empty?
146
+ end
147
+ end; end
@@ -1,6 +1,5 @@
1
1
 
2
- module Rib; end
3
- module Rib::Auto
2
+ module Rib; module Auto
4
3
  module_function
5
4
  def load
6
5
  app, name = %w[rails rack].find{ |n|
@@ -20,4 +19,4 @@ module Rib::Auto
20
19
  Rib.warn("No app found")
21
20
  end
22
21
  end
23
- end
22
+ end; end
@@ -1,6 +1,5 @@
1
1
 
2
- module Rib; end
3
- module Rib::Rack
2
+ module Rib; module Rack
4
3
  singleton_class.module_eval{ attr_accessor :app }
5
4
 
6
5
  module_function
@@ -26,4 +25,4 @@ module Rib::Rack
26
25
  def configru_path
27
26
  "#{Rib.config[:prefix]}/config.ru"
28
27
  end
29
- end
28
+ end; end
@@ -1,6 +1,5 @@
1
1
 
2
- module Rib; end
3
- module Rib::Rails
2
+ module Rib; module Rails
4
3
  module_function
5
4
  def load
6
5
  load_rails
@@ -113,4 +112,4 @@ module Rib::Rails
113
112
  def path_for file
114
113
  File.expand_path("#{Rib.config[:prefix]}/config/#{file}")
115
114
  end
116
- end
115
+ end; end
@@ -1,28 +1,21 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::Completion
5
- extend Rib::Plugin
4
+ module Rib; module Completion
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
9
9
 
10
10
  def before_loop
11
11
  return super if Completion.disabled?
12
- config[:completion] ||= {}
13
- config[:completion][:eval_binding] ||= method(:eval_binding).to_proc
14
- (config[:completion][:gems] ||= []).concat(ripl_plugins)
12
+ config[:completion] ||= {}
13
+ config[:completion][:gems] ||= []
14
+ config[:completion][:eval_binding] ||= method(:eval_binding).to_proc
15
15
  Rib.silence{Bond.start(config[:completion]) unless Bond.started?}
16
16
  super
17
17
  end
18
-
19
-
20
-
21
- private
22
- def ripl_plugins
23
- $LOADED_FEATURES.map{ |e| e[/ripl\/[^\/]+$/] }.compact
24
- end
25
- end
18
+ end; end
26
19
 
27
20
  begin
28
21
  Rib.silence{require 'bond'}
@@ -2,8 +2,8 @@
2
2
  require 'rib'
3
3
  require 'fileutils'
4
4
 
5
- module Rib::History
6
- extend Rib::Plugin
5
+ module Rib; module History
6
+ extend Plugin
7
7
  Shell.use(self)
8
8
 
9
9
  # --------------- Rib API ---------------
@@ -63,4 +63,4 @@ module Rib::History
63
63
  def history_size
64
64
  config[:history_size] ||= 500
65
65
  end
66
- end
66
+ end; end
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::LastValue
5
- extend Rib::Plugin
4
+ module Rib; module LastValue
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  attr_reader :last_value, :last_exception
@@ -32,4 +32,4 @@ module Rib::LastValue
32
32
  end
33
33
 
34
34
  Rib.extend(Imp)
35
- end
35
+ end; end
@@ -2,8 +2,8 @@
2
2
  require 'rib'
3
3
 
4
4
  # from https://github.com/janlelis/ripl-multi_line
5
- module Rib::Multiline
6
- extend Rib::Plugin
5
+ module Rib; module Multiline
6
+ extend Plugin
7
7
  Shell.use(self)
8
8
 
9
9
  engine = if Object.const_defined?(:RUBY_ENGINE)
@@ -129,4 +129,4 @@ module Rib::Multiline
129
129
  def multiline_buffer
130
130
  @multiline_buffer ||= []
131
131
  end
132
- end
132
+ end; end
@@ -2,8 +2,8 @@
2
2
  require 'rib'
3
3
  require 'readline'
4
4
 
5
- module Rib::Readline
6
- extend Rib::Plugin
5
+ module Rib; module Readline
6
+ extend Plugin
7
7
  Shell.use(self)
8
8
 
9
9
  # --------------- Rib API ---------------
@@ -24,4 +24,4 @@ unless ::Readline::HISTORY.respond_to?(:last)
24
24
  def (::Readline::HISTORY).last
25
25
  self[-1]
26
26
  end
27
- end
27
+ end; end
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib/core/history' # dependency
3
3
 
4
- module Rib::SqueezeHistory
5
- extend Rib::Plugin
4
+ module Rib; module SqueezeHistory
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
@@ -42,4 +42,4 @@ module Rib::SqueezeHistory
42
42
  end
43
43
  }
44
44
  end
45
- end
45
+ end; end
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::StripBacktrace
5
- extend Rib::Plugin
4
+ module Rib; module StripBacktrace
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
@@ -42,4 +42,4 @@ module Rib::StripBacktrace
42
42
  def replace_path_prefix prefix, substitute, path
43
43
  path.sub(/\A#{Regexp.escape(prefix)}\//, substitute)
44
44
  end
45
- end
45
+ end; end
@@ -3,8 +3,8 @@ require 'rib/core/history' # otherwise the order might be wrong
3
3
  require 'rib/core/readline' # dependency
4
4
  require 'rib/core/multiline' # dependency
5
5
 
6
- module Rib::Autoindent
7
- extend Rib::Plugin
6
+ module Rib; module Autoindent
7
+ extend Plugin
8
8
  Shell.use(self)
9
9
 
10
10
  # begin block could be simpler, because it should also trigger
@@ -153,7 +153,7 @@ module Rib::Autoindent
153
153
  def autoindent_stack
154
154
  @autoindent_stack ||= []
155
155
  end
156
- end
156
+ end; end
157
157
 
158
158
  begin
159
159
  require 'readline_buffer'
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::Hirb
5
- extend Rib::Plugin
4
+ module Rib; module Hirb
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
@@ -24,4 +24,4 @@ rescue LoadError => e
24
24
  " gem install hirb\n" ,
25
25
  "Or add hirb to Gemfile if that's the case")
26
26
  Rib::Hirb.disable
27
- end
27
+ end; end
@@ -1,8 +1,8 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::Paging
5
- extend Rib::Plugin
4
+ module Rib; module Paging
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
@@ -36,7 +36,7 @@ module Rib::Paging
36
36
  def pager
37
37
  ENV['PAGER'] || 'less -R'
38
38
  end
39
- end
39
+ end; end
40
40
 
41
41
  pager = ENV['PAGER'] || 'less'
42
42
 
@@ -1,15 +1,15 @@
1
1
 
2
2
  require 'rib'
3
3
 
4
- module Rib::Anchor
5
- extend Rib::Plugin
4
+ module Rib; module Anchor
5
+ extend Plugin
6
6
  Shell.use(self)
7
7
 
8
8
  # --------------- Rib API ---------------
9
9
 
10
10
  def prompt
11
11
  return super if Rib::Anchor.disabled?
12
- return super unless config[:prompt_anchor]
12
+ return super unless anchor?
13
13
 
14
14
  level = "(#{Rib.shells.size - 1})"
15
15
  if Rib.const_defined?(:Color) &&
@@ -22,6 +22,10 @@ module Rib::Anchor
22
22
  end
23
23
  end
24
24
 
25
+ def anchor?
26
+ !!config[:prompt_anchor]
27
+ end
28
+
25
29
 
26
30
 
27
31
  private
@@ -67,7 +71,12 @@ module Rib::Anchor
67
71
  ensure
68
72
  Rib.shells.pop
69
73
  end
74
+
75
+ def stop_anchors
76
+ Rib.shells.select(&:anchor?).each(&:stop)
77
+ Rib::Skip
78
+ end
70
79
  end
71
80
 
72
81
  Rib.extend(Imp)
73
- end
82
+ end; end