rib 1.0.0 → 1.0.1

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.
data/CHANGES.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # CHANGES
2
2
 
3
+ ## Rib 1.0.1 -- 2011-12-15
4
+
5
+ ### Incompatible changes
6
+
7
+ * [rib] Keyword `quit` to exit rib is removed, preferring `exit`.
8
+
9
+ ### Bugs fixes
10
+
11
+ * [rib] Now you exit rib with ` exit`. Thanks @ayamomiji
12
+ * [rib] Fixed -e, --eval binding. It should be TOPLEVEL_BINDING
13
+
14
+ ### Enhancement
15
+
16
+ * [core/history, more/color, more/multiline_history_file, extra/autoindent]
17
+ Make sure values are initialized even if before_loop is called later.
18
+ This helps us enable plugins on the fly.
19
+
20
+ * [extra/autoindent] Now it depends on history plugin as well. This is not
21
+ really needed, but would help to reduce plugins ordering issue.
22
+
3
23
  ## Rib 1.0.0 -- 2011-11-05
4
24
 
5
25
  ### Bugs fixes
data/README.md CHANGED
@@ -5,7 +5,7 @@ by Lin Jen-Shin ([godfat](http://godfat.org))
5
5
  ## LINKS:
6
6
 
7
7
  * [github](https://github.com/godfat/rib)
8
- * [rubygems](http://rubygems.org/gems/rib)
8
+ * [rubygems](https://rubygems.org/gems/rib)
9
9
  * [rdoc](http://rdoc.info/github/godfat/rib)
10
10
 
11
11
  ## DESCRIPTION:
@@ -143,7 +143,7 @@ Rib.config[:name] | The name of this shell
143
143
  Rib.config[:result_prompt] | Default is "=>"
144
144
  Rib.config[:prompt] | Default is ">>"
145
145
  Rib.config[:binding] | Context, default: TOPLEVEL_BINDING
146
- Rib.config[:exit] | Commands to exit, default [nil, 'exit', 'quit']
146
+ Rib.config[:exit] | Commands to exit, default [nil] # control+d
147
147
 
148
148
  #### Plugin specific configuration
149
149
 
@@ -203,6 +203,15 @@ more plugins are lying in `rib/more/*.rb`. You can read `rib/app/ramaze.rb`
203
203
  and `bin/rib-ramaze` as a Rib App reference implementation, because it's very
204
204
  simple, simpler than rib-rails.
205
205
 
206
+ ## CONTRIBUTORS:
207
+
208
+ * Andrew Liu (@eggegg)
209
+ * ayaya (@ayamomiji)
210
+ * Lin Jen-Shin (@godfat)
211
+ * Mr. Big Cat (@miaout17)
212
+ * @bootleq
213
+ * @tka
214
+
206
215
  ## LICENSE:
207
216
 
208
217
  Apache License 2.0
@@ -64,6 +64,8 @@ module Rib::API
64
64
  # Evaluate the input using #loop_eval and handle it
65
65
  def eval_input input
66
66
  [loop_eval(input), nil]
67
+ rescue SystemExit
68
+ throw(:rib_exit, input)
67
69
  rescue Exception => e
68
70
  [nil, e]
69
71
  ensure
@@ -10,8 +10,8 @@ module Rib::History
10
10
 
11
11
  def before_loop
12
12
  return super if History.disabled?
13
- config[:history_file] ||= File.join(Rib.home, 'history.rb')
14
- config[:history_size] ||= 500
13
+ history_file
14
+ history_size
15
15
  FileUtils.mkdir_p(File.dirname(history_file_path))
16
16
  read_history
17
17
  Rib.say("History read from: #{history_file_path}") if $VERBOSE
@@ -46,13 +46,21 @@ module Rib::History
46
46
  def write_history
47
47
  return super if History.disabled?
48
48
  File.open(history_file_path, 'w'){ |f|
49
- f.puts(history.to_a.last(config[:history_size]).join("\n")) }
49
+ f.puts(history.to_a.last(history_size).join("\n")) }
50
50
  end
51
51
 
52
52
 
53
53
 
54
54
  private
55
+ def history_file
56
+ config[:history_file] ||= File.join(Rib.home, 'history.rb')
57
+ end
58
+
55
59
  def history_file_path
56
- config[:history_file_path] ||= File.expand_path(config[:history_file])
60
+ config[:history_file_path] ||= File.expand_path(history_file)
61
+ end
62
+
63
+ def history_size
64
+ config[:history_size] ||= 500
57
65
  end
58
66
  end
@@ -1,4 +1,5 @@
1
1
 
2
+ require 'rib/core/history' # otherwise the order might be wrong
2
3
  require 'rib/core/readline' # dependency
3
4
  require 'rib/core/multiline' # dependency
4
5
 
@@ -62,7 +63,7 @@ module Rib::Autoindent
62
63
 
63
64
  def before_loop
64
65
  return super if Autoindent.disabled?
65
- config[:autoindent_spaces] ||= ' '
66
+ autoindent_spaces
66
67
  super
67
68
  end
68
69
 
@@ -145,7 +146,11 @@ module Rib::Autoindent
145
146
 
146
147
  private
147
148
  def current_autoindent size=autoindent_stack.size
148
- config[:autoindent_spaces] * size
149
+ autoindent_spaces * size
150
+ end
151
+
152
+ def autoindent_spaces
153
+ config[:autoindent_spaces] ||= ' '
149
154
  end
150
155
 
151
156
  def autoindent_stack
@@ -8,6 +8,18 @@ module Rib::Color
8
8
  # --------------- Rib API ---------------
9
9
 
10
10
  def before_loop
11
+ colors
12
+ super
13
+ end
14
+
15
+ def format_result result
16
+ return super if Color.disabled?
17
+ config[:result_prompt] + format_color(result)
18
+ end
19
+
20
+ # --------------- Plugin API ---------------
21
+
22
+ def colors
11
23
  config[:color] ||= {
12
24
  Numeric => :red ,
13
25
  String => :green ,
@@ -18,20 +30,9 @@ module Rib::Color
18
30
  TrueClass => :magenta,
19
31
  FalseClass => :magenta,
20
32
  Exception => :magenta,
21
- Object => :yellow
22
- }
23
- super
24
- end
25
-
26
- def format_result result
27
- return super if Color.disabled?
28
- config[:result_prompt] + format_color(result)
33
+ Object => :yellow }
29
34
  end
30
35
 
31
- # --------------- Plugin API ---------------
32
-
33
- def colors; config[:color]; end
34
-
35
36
  def format_color result, display=result.inspect
36
37
  case result
37
38
  when String ; send(colors[String ]){ display }
@@ -9,7 +9,7 @@ module Rib::MultilineHistoryFile
9
9
 
10
10
  def before_loop
11
11
  return super if MultilineHistoryFile.disabled?
12
- config[:multiline_history_file_token] ||= ' '
12
+ multiline_history_file_token
13
13
  super
14
14
  end
15
15
 
@@ -23,7 +23,7 @@ module Rib::MultilineHistoryFile
23
23
  if line.end_with?(
24
24
  "#{config[:multiline_history_file_token]}\n")
25
25
  buffer << line[0...
26
- -config[:multiline_history_file_token].size-1] + "\n"
26
+ -multiline_history_file_token.size-1] + "\n"
27
27
  else
28
28
  history << (buffer.join + line).chomp
29
29
  buffer = []
@@ -39,4 +39,11 @@ module Rib::MultilineHistoryFile
39
39
  }
40
40
  super
41
41
  end
42
+
43
+
44
+
45
+ private
46
+ def multiline_history_file_token
47
+ config[:multiline_history_file_token] ||= ' '
48
+ end
42
49
  end
@@ -81,7 +81,7 @@ module Rib::Runner
81
81
  until argv.empty?
82
82
  case arg = argv.shift
83
83
  when /^-e=?(.+)?/, /^--eval=?(.+)?/
84
- eval($1 || argv.shift, binding, __FILE__, __LINE__)
84
+ eval($1 || argv.shift, TOPLEVEL_BINDING, __FILE__, __LINE__)
85
85
 
86
86
  when /^-d/, '--debug'
87
87
  $DEBUG = true
@@ -13,12 +13,11 @@ class Rib::Shell
13
13
  attr_reader :config
14
14
  def initialize(config={})
15
15
  self.config = {
16
- :result_prompt => '=> ' ,
17
- :prompt => '>> ' ,
18
- :binding => TOPLEVEL_BINDING ,
19
- :exit => [nil, 'exit', 'quit'],
20
- :line => 1
21
- }.merge(config)
16
+ :result_prompt => '=> ' ,
17
+ :prompt => '>> ' ,
18
+ :binding => TOPLEVEL_BINDING,
19
+ :exit => [nil] ,
20
+ :line => 1 }.merge(config)
22
21
  @running = false
23
22
  end
24
23
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module Rib
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "rib"
5
- s.version = "1.0.0"
5
+ s.version = "1.0.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = "2011-11-05"
9
+ s.date = "2011-12-15"
10
10
  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"
11
11
  s.email = ["godfat (XD) godfat.org"]
12
12
  s.executables = [
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
21
21
  ".gitmodules",
22
22
  ".travis.yml",
23
23
  "CHANGES.md",
24
- "CONTRIBUTORS",
25
24
  "Gemfile",
26
25
  "LICENSE",
27
26
  "README.md",
@@ -81,7 +80,7 @@ Gem::Specification.new do |s|
81
80
  "test/test_shell.rb"]
82
81
  s.homepage = "https://github.com/godfat/rib"
83
82
  s.require_paths = ["lib"]
84
- s.rubygems_version = "1.8.11"
83
+ s.rubygems_version = "1.8.12"
85
84
  s.summary = "Ruby-Interactive-ruBy -- Yet another interactive Ruby shell"
86
85
  s.test_files = [
87
86
  "test/core/test_completion.rb",
@@ -26,12 +26,20 @@ describe Rib::Color do
26
26
 
27
27
  # regression test
28
28
  should "colorize errors with `/' inside" do
29
+ i = if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
30
+ 1
31
+ else
32
+ 0
33
+ end
34
+
29
35
  begin
30
36
  line = __LINE__; 1/0
31
37
  rescue ZeroDivisionError => e
32
- Rib::Color.colorize_backtrace(e.backtrace).first.should.end_with? \
33
- "test/more/#{Rib::Color.yellow{'test_color.rb'}}:" \
34
- "#{Rib::Color.red{line}}:in #{Rib::Color.green{"`/'"}}"
38
+ msg = "test/more/#{Rib::Color.yellow{'test_color.rb'}}:" \
39
+ "#{Rib::Color.red{line}}:in #{Rib::Color.green}"
40
+ Rib::Color.colorize_backtrace(e.backtrace)[i].should =~ \
41
+ Regexp.new(
42
+ "#{Regexp.escape(msg)}`.+'#{Regexp.escape(Rib::Color.reset)}")
35
43
  end
36
44
  end
37
45
  end
@@ -16,9 +16,11 @@ describe Rib::Shell do
16
16
  @shell.loop
17
17
  true.should.eq true
18
18
  end
19
- should 'exit' do input('exit') end
20
- should 'quit' do input('quit') end
21
- should 'ctrl+d' do mock(@shell).puts; input(nil) end
19
+ should 'exit' do input('exit' ) end
20
+ 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
22
24
  end
23
25
 
24
26
  describe '#loop_once' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
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: 2011-11-05 00:00:00.000000000 Z
12
+ date: 2011-12-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
15
15
 
@@ -44,7 +44,6 @@ files:
44
44
  - .gitmodules
45
45
  - .travis.yml
46
46
  - CHANGES.md
47
- - CONTRIBUTORS
48
47
  - Gemfile
49
48
  - LICENSE
50
49
  - README.md
@@ -122,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
121
  version: '0'
123
122
  requirements: []
124
123
  rubyforge_project:
125
- rubygems_version: 1.8.11
124
+ rubygems_version: 1.8.12
126
125
  signing_key:
127
126
  specification_version: 3
128
127
  summary: Ruby-Interactive-ruBy -- Yet another interactive Ruby shell
@@ -1,2 +0,0 @@
1
- Lin Jen-Shin (godfat)
2
- miaout17 (miaout17)