dietrb 0.4.4 → 0.4.5

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/README.rdoc CHANGED
@@ -11,6 +11,14 @@ not grow too much more. For now my things to-do are .irbrc support, completion,
11
11
  and investigate what else people really really need. After that it's time to
12
12
  polish.
13
13
 
14
+ = Important notice
15
+
16
+ Since on Ruby 1.9 *all* latest gems are pushed onto the load path by default,
17
+ installing the DietRB gem would break the existing IRB binary. Therefor, with
18
+ the DietRB gem is installed, it will hijack the `irb' bin file.
19
+
20
+ The original IRB will still work when you uninstall the DietRB gem, though.
21
+
14
22
  == Extensions
15
23
 
16
24
  * irb/ext/colorize.rb, adds support for colorizing the prompt and result. The
data/Rakefile CHANGED
@@ -3,7 +3,8 @@ task :default => :run
3
3
  desc "Run the specs"
4
4
  task :spec do
5
5
  # sh "macbacon #{FileList['spec/**/*_spec.rb'].join(' ')}"
6
- sh "bacon19 #{FileList['spec/**/*_spec.rb'].join(' ')}"
6
+ bacon = `which bacon19 || which bacon`.chomp
7
+ sh "#{bacon} #{FileList['spec/**/*_spec.rb'].join(' ')}"
7
8
  end
8
9
 
9
10
  desc "Run specs with Kicker"
@@ -13,7 +14,8 @@ end
13
14
 
14
15
  desc "Run dietrb with ruby19"
15
16
  task :run do
16
- sh "ruby19 -Ilib ./bin/dietrb -r irb/ext/colorize -r pp"
17
+ ruby = `which ruby19 || which ruby`.chomp
18
+ sh "#{ruby} -Ilib ./bin/dietrb -r irb/ext/colorize -r pp"
17
19
  end
18
20
 
19
21
  desc "AOT compile for MacRuby"
@@ -45,4 +47,4 @@ begin
45
47
  gemspec.files.reject! { |file| file =~ /^(extensions|\.gitignore)/ }
46
48
  end
47
49
  rescue LoadError
48
- end
50
+ end
data/bin/dietrb CHANGED
@@ -5,9 +5,12 @@ require 'irb'
5
5
  unless ARGV.empty?
6
6
  require 'optparse'
7
7
 
8
+ ignore_irbrc = false
9
+
8
10
  OptionParser.new do |opt|
9
11
  bin = File.basename($0)
10
12
  opt.banner = "Usage: #{bin} [options] [programfile] [arguments]"
13
+ opt.on("-f", "Ignore ~/.irbrc") { |ignore| ignore_irbrc = ignore }
11
14
  opt.on("-r load-lib", "Loads the given library (same as `ruby -r')") { |lib| require lib }
12
15
  opt.on("-d", "Set $DEBUG to true (same as `ruby -d')") { $DEBUG = true }
13
16
  opt.on("-I path", "Add path to $LOAD_PATH") { |path| $LOAD_PATH.unshift(path) }
@@ -20,8 +23,10 @@ unless ARGV.empty?
20
23
  end.parse!(ARGV)
21
24
  end
22
25
 
23
- irbrc = File.expand_path("~/.irbrc")
24
- load(irbrc) if File.exist?(irbrc)
26
+ unless ignore_irbrc
27
+ irbrc = File.expand_path("~/.irbrc")
28
+ load(irbrc) if File.exist?(irbrc)
29
+ end
25
30
 
26
31
  IRB.formatter.filter_from_backtrace << /^#{__FILE__}/
27
32
 
data/dietrb.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dietrb}
8
- s.version = "0.4.4"
8
+ s.version = "0.4.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Eloy Duran"]
data/lib/irb/context.rb CHANGED
@@ -85,7 +85,7 @@ module IRB
85
85
  # process_line("quit") # => false
86
86
  def process_line(line)
87
87
  @source << line
88
- return false if @source.to_s == "quit"
88
+ return false if @source.terminate?
89
89
 
90
90
  if @source.syntax_error?
91
91
  puts formatter.syntax_error(@line, @source.syntax_error)
@@ -129,4 +129,4 @@ module Kernel
129
129
  end
130
130
 
131
131
  private :irb
132
- end
132
+ end
data/lib/irb/source.rb CHANGED
@@ -51,6 +51,11 @@ module IRB
51
51
  def syntax_error?
52
52
  reflect.syntax_error?
53
53
  end
54
+
55
+ # Reflects on the accumulated source to see if it contains a terminate signal.
56
+ def terminate?
57
+ reflect.terminate?
58
+ end
54
59
 
55
60
  # Reflects on the accumulated source and returns the actual syntax error
56
61
  # message if one occurs.
@@ -110,6 +115,20 @@ module IRB
110
115
  def syntax_error?
111
116
  !@syntax_error.nil?
112
117
  end
118
+
119
+ # Returns whether or not the source contains a call to toplevel
120
+ # quit or exit, namely if the current session should be terminated
121
+ #
122
+ # For example, this would terminate the session
123
+ #
124
+ # def foo; end; quit
125
+ #
126
+ # This does not:
127
+ #
128
+ # def foo; quit; end
129
+ def terminate?
130
+ !@terminate.nil?
131
+ end
113
132
 
114
133
  UNEXPECTED_END = "syntax error, unexpected $end"
115
134
 
@@ -120,6 +139,7 @@ module IRB
120
139
  end
121
140
 
122
141
  INCREASE_LEVEL_KEYWORDS = %w{ class module def begin if unless case while for do }
142
+ TERMINATE_KEYWORDS = %w{ exit quit }
123
143
 
124
144
  def on_kw(token) #:nodoc:
125
145
  case token
@@ -145,6 +165,14 @@ module IRB
145
165
  @level += 1
146
166
  super
147
167
  end
168
+
169
+ def on_ident(token) #:nodoc:
170
+ if @level == 0 && TERMINATE_KEYWORDS.include?(token)
171
+ @terminate = true
172
+ else
173
+ super
174
+ end
175
+ end
148
176
 
149
177
  def on_lbrace(token) #:nodoc:
150
178
  @level += 1
@@ -157,4 +185,4 @@ module IRB
157
185
  end
158
186
  end
159
187
  end
160
- end
188
+ end
data/lib/irb/version.rb CHANGED
@@ -8,7 +8,7 @@ module IRB
8
8
  module VERSION #:nodoc:
9
9
  MAJOR = 0
10
10
  MINOR = 4
11
- TINY = 4
11
+ TINY = 5
12
12
 
13
13
  STRING = [MAJOR, MINOR, TINY].join('.')
14
14
  DESCRIPTION = "#{STRING} (DietRB)"
data/lib/irb.rb CHANGED
@@ -16,3 +16,17 @@ require 'irb/ext/completion'
16
16
  if !ENV['SPECCING'] && defined?(RUBY_ENGINE) && RUBY_ENGINE == "macruby"
17
17
  require 'irb/ext/macruby'
18
18
  end
19
+
20
+ module IRB
21
+ class << self
22
+ # This is just here for so the ruby 1.9 IRB will seemingly work, but actually
23
+ # loads DietRB, how cunning...
24
+ #
25
+ # This will obviously be removed once we've conquered the world.
26
+ def start(*)
27
+ warn "[!] Note that you are now actually using DietRB (#{IRB::VERSION::STRING})\n"
28
+ load File.expand_path('../../bin/dietrb', __FILE__)
29
+ end
30
+ alias_method :setup, :start
31
+ end
32
+ end
data/spec/context_spec.rb CHANGED
@@ -241,4 +241,4 @@ describe "Kernel::irb" do
241
241
  irb(o)
242
242
  IRBRan.should == o
243
243
  end
244
- end
244
+ end
data/spec/source_spec.rb CHANGED
@@ -130,6 +130,16 @@ describe "IRB::Source::Reflector" do
130
130
  reflect("if true").should.not.be.code_block
131
131
  reflect("p :ok if true").should.be.code_block
132
132
  end
133
+
134
+ it "returns whether or not the current session should be terminated" do
135
+ reflect("exit").should.terminate
136
+ reflect("quit").should.terminate
137
+ reflect("def foo; end; exit").should.terminate
138
+ reflect("def foo; end; quit").should.terminate
139
+
140
+ reflect("def foo; exit; end").should.not.terminate
141
+ reflect("def foo; quit; end").should.not.terminate
142
+ end
133
143
 
134
144
  it "returns whether or not the source contains a syntax error, except a code block not ending" do
135
145
  reflect("def;").should.have.syntax_error
@@ -187,4 +197,4 @@ describe "IRB::Source::Reflector" do
187
197
  reflect("#{open}\n#{close}").level.should == 0
188
198
  end
189
199
  end
190
- end
200
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dietrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Duran