Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

change readline plugins to classes, fix accidental Readline.setup calls

  • Loading branch information...
commit 8262eebac20f1e47f2fd9a06a3d3fccaaa4d967f 1 parent 2fc5540
@cldwalker authored
View
5 lib/bond/agent.rb
@@ -79,8 +79,7 @@ def reset
protected
def setup_readline_plugin(plugin)
- raise ArgumentError unless plugin.is_a?(Module)
- @weapon = plugin.extend(plugin)
+ @weapon = plugin
@weapon.setup(self)
rescue
$stderr.puts "Bond Error: Failed #{plugin.to_s[/[^:]+$/]} setup with '#{$!.message}'"
@@ -104,4 +103,4 @@ def completion_error(desc, message)
arr
end
end
-end
+end
View
4 lib/bond/m.rb
@@ -47,9 +47,7 @@ def spy(input)
# Validates and sets values in M.config.
def debrief(options={})
config.merge! options
- plugin_methods = %w{setup line_buffer}
- unless config[:readline_plugin].is_a?(Module) &&
- plugin_methods.all? {|e| config[:readline_plugin].instance_methods.map {|f| f.to_s}.include?(e)}
+ unless %w{setup line_buffer}.all? {|e| config[:readline_plugin].respond_to?(e) }
$stderr.puts "Bond Error: Invalid readline plugin given."
end
end
View
8 lib/bond/rawline.rb
@@ -1,16 +1,16 @@
module Bond
# A readline plugin for use with {Rawline}[http://github.com/h3rald/rawline]. This plugin
# should be used in conjunction with {a Rawline shell}[http://www.h3rald.com/articles/real-world-rawline-usage].
- module Rawline
- def setup(agent)
+ class Rawline
+ def self.setup(agent)
require 'rawline'
::Rawline.completion_append_character = nil
::Rawline.basic_word_break_characters= " \t\n\"\\'`><;|&{("
::Rawline.completion_proc = agent
end
- def line_buffer
+ def self.line_buffer
::Rawline.editor.line.text
end
end
-end
+end
View
10 lib/bond/readline.rb
@@ -1,11 +1,11 @@
module Bond
# This is the default readline plugin for Bond. A valid plugin must be a module that defines methods setup
# and line_buffer as described below.
- module Readline
+ class Readline
DefaultBreakCharacters = " \t\n\"\\'`><=;|&{("
# Loads the readline-like library and sets the completion_proc to the given agent.
- def setup(agent)
+ def self.setup(agent)
if RUBY_PLATFORM[/mswin|mingw|bccwin|wince/i]
require 'rb-readline'
else
@@ -27,7 +27,7 @@ def setup(agent)
end
end
- def load_jruby_extension
+ def self.load_jruby_extension
require 'jruby'
class << ::Readline
@@ -38,14 +38,14 @@ def line_buffer
end
end
- def load_extension
+ def self.load_extension
require 'readline_line_buffer'
rescue LoadError
$stderr.puts "Bond Error: Failed to load readline_line_buffer. Ensure that it exists and was built correctly."
end
# Returns full line of what the user has typed.
- def line_buffer
+ def self.line_buffer
::Readline.line_buffer
end
end
View
3  test/agent_test.rb
@@ -210,7 +210,8 @@ def complete_prints_error(msg, *args, &block)
describe "spy" do
before_all {
- M.reset; complete(:on=>/end$/) { [] };
+ reset
+ complete(:on=>/end$/) { [] };
complete(:all_methods=>true); complete(:method=>'the') { %w{spy who loved me} }
complete(:object=>"Symbol")
}
View
6 test/bond_test.rb
@@ -48,7 +48,7 @@ def start(options={}, &block)
Bond.started?.should == true
end
- after_all { M.debrief :readline_plugin=>valid_readline_plugin; M.reset }
+ after_all { reset }
end
describe "start with :gems" do
@@ -88,7 +88,7 @@ def start(options={}, &block)
M.expects(:gem)
start(:gems=>%w{awesome})
end
- after_all { M.debrief :readline_plugin=>valid_readline_plugin; M.reset }
+ after_all { reset }
end
it "prints error if Readline setup fails" do
@@ -105,7 +105,7 @@ def start(options={}, &block)
it "reset clears existing missions" do
complete(:on=>/blah/) {[]}
Bond.agent.missions.size.should.not == 0
- M.reset
+ reset
Bond.agent.missions.size.should == 0
end
View
2  test/completion_test.rb
@@ -2,7 +2,7 @@
describe "Completion" do
before_all {
- M.reset
+ reset
M.load_file File.dirname(__FILE__) + '/../lib/bond/completion.rb'
M.load_dir File.dirname(__FILE__) + '/../lib/bond'
}
View
2  test/completions_test.rb
@@ -2,7 +2,7 @@
describe "completions for" do
before_all {
- M.reset
+ reset
complete(:all_methods=>true)
complete(:all_operator_methods=>true)
M.load_file File.dirname(__FILE__) + '/../lib/bond/completion.rb'
View
7 test/test_helper.rb
@@ -51,7 +51,12 @@ def complete(*args, &block)
end
def valid_readline_plugin
- Module.new{ def setup(arg); end; def line_buffer; end }
+ Class.new { def self.setup(arg); end; def self.line_buffer; end }
+ end
+
+ def reset
+ M.reset
+ M.debrief :readline_plugin => TestHelpers.valid_readline_plugin
end
end

0 comments on commit 8262eeb

Please sign in to comment.
Something went wrong with that request. Please try again.