Skip to content

Commit

Permalink
rename :readline_plugin option to :readline
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Jan 10, 2011
1 parent 3bd58d4 commit 85ceedc
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/bond.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def config; M.config; end
# @option options [Array<String>] :gems Gems which have their completions loaded from
# @gem_source/lib/bond/completions/*.rb. If gem is a plugin gem i.e. ripl-plugin, completion will be loaded
# from @gem_source/lib/ripl/completions/plugin.rb.
# @option options [Module, Symbol] :readline_plugin (Bond::Readline) Specifies a Bond readline plugin.
# @option options [Module, Symbol] :readline (Bond::Readline) Specifies a Bond readline plugin.
# A symbol points to a capitalized Bond constant i.e. :ruby -> Bond::Ruby.
# Available plugins are Bond::Readline, Bond::Ruby, Bond::Jruby and Bond::Rawline.
# @option options [Proc] :default_mission (DefaultMission) Sets default completion to use when no missions match.
Expand Down
4 changes: 2 additions & 2 deletions lib/bond/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Agent
attr_reader :weapon

def initialize(options={}) #@private
setup_readline_plugin(options[:readline_plugin])
setup_readline(options[:readline])
@default_mission_action = options[:default_mission] if options[:default_mission]
Mission.eval_binding = options[:eval_binding] if options[:eval_binding]
Search.default_search = options[:default_search] || :normal
Expand Down Expand Up @@ -78,7 +78,7 @@ def reset
end

protected
def setup_readline_plugin(plugin)
def setup_readline(plugin)
@weapon = plugin
@weapon.setup(self)
rescue
Expand Down
2 changes: 1 addition & 1 deletion lib/bond/completions/bond.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
["on", "method", "methods", "class", "object", "anywhere", "prefix", "search", "action", "place", "name"]
}
complete(:methods=>['Bond.start', 'Bond.restart']) {
%w{gems readline_plugin default_mission default_search eval_binding debug eval_debug bare}
%w{gems readline default_mission default_search eval_binding debug eval_debug bare}
}
15 changes: 7 additions & 8 deletions lib/bond/m.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ def spy(input)
# Validates and sets values in M.config.
def debrief(options={})
config.merge! options
config[:readline_plugin] ||= default_readline_plugin
if !config[:readline_plugin].is_a?(Module) &&
Bond.const_defined?(config[:readline_plugin].to_s.capitalize)
config[:readline_plugin] = Bond.const_get(
config[:readline_plugin].to_s.capitalize)
config[:readline] ||= default_readline
if !config[:readline].is_a?(Module) &&
Bond.const_defined?(config[:readline].to_s.capitalize)
config[:readline] = Bond.const_get(config[:readline].to_s.capitalize)
end
unless %w{setup line_buffer}.all? {|e| config[:readline_plugin].respond_to?(e) }
$stderr.puts "Bond Error: Invalid readline plugin '#{config[:readline_plugin]}'."
unless %w{setup line_buffer}.all? {|e| config[:readline].respond_to?(e) }
$stderr.puts "Bond Error: Invalid readline plugin '#{config[:readline]}'."
end
end

Expand Down Expand Up @@ -114,7 +113,7 @@ def home
end

protected
def default_readline_plugin
def default_readline
RUBY_PLATFORM[/mswin|mingw|bccwin|wince/i] ? Ruby :
RUBY_PLATFORM[/java/i] ? Jruby : Bond::Readline
end
Expand Down
28 changes: 14 additions & 14 deletions test/bond_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,29 @@
describe "Bond" do
describe "start" do
def start(options={}, &block)
Bond.start({:readline_plugin=>valid_readline_plugin}.merge(options), &block)
Bond.start({:readline=>valid_readline}.merge(options), &block)
end

before { M.instance_eval("@started = @agent = @config = nil"); M.expects(:load_completions) }
it "prints error if readline_plugin doesn't have all required methods" do
it "prints error if readline doesn't have all required methods" do
capture_stderr {
start :readline_plugin=>Module.new{ def self.setup(arg); end }
start :readline=>Module.new{ def self.setup(arg); end }
}.should =~ /Invalid/
end

it "prints error if readline_plugin symbol is invalid" do
it "prints error if readline symbol is invalid" do
capture_stderr {
start :readline_plugin => :blah
start :readline => :blah
}.should =~ /Invalid.*'blah'/
end

it "prints no error if valid readline_plugin" do
it "prints no error if valid readline" do
capture_stderr { start }.should == ''
end

it 'prints no error if valid readline_plugin symbol' do
capture_stderr { start :readline_plugin => :ruby }.should == ''
Bond.config[:readline_plugin].should == Bond::Ruby
it 'prints no error if valid readline symbol' do
capture_stderr { start :readline => :ruby }.should == ''
Bond.config[:readline].should == Bond::Ruby
end

it "sets default mission" do
Expand Down Expand Up @@ -102,8 +102,8 @@ def start(options={}, &block)

it "prints error if Readline setup fails" do
Bond::Readline.expects(:setup).raises('WTF')
capture_stderr { Bond.start(:readline_plugin=>Bond::Readline) }.should =~ /Error.*Failed Readline.*'WTF'/
M.debrief :readline_plugin=>valid_readline_plugin
capture_stderr { Bond.start(:readline=>Bond::Readline) }.should =~ /Error.*Failed Readline.*'WTF'/
M.debrief :readline=>valid_readline
end

it "start prints error for failed completion file" do
Expand All @@ -120,21 +120,21 @@ def start(options={}, &block)

describe "restart" do
def start(options={}, &block)
Bond.start({:readline_plugin=>valid_readline_plugin}.merge(options), &block)
Bond.start({:readline=>valid_readline}.merge(options), &block)
end

it "deletes previous config" do
start :blah=>''
Bond.config[:blah].should.not == nil
Bond.restart({:readline_plugin=>valid_readline_plugin})
Bond.restart({:readline=>valid_readline})
Bond.config[:blah].should == nil
end

it "deletes previous method completions" do
start
complete(:method=>'blah') { [] }
MethodMission.actions['blah'].should.not == nil
Bond.restart({:readline_plugin=>valid_readline_plugin})
Bond.restart({:readline=>valid_readline})
MethodMission.actions['blah'].should == nil
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/completion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
end

it "completes hash coming from a method" do
tab('Bond.config[:r').should == ["Bond.config[:readline_plugin"]
tab('Bond.config[:r').should == ["Bond.config[:readline"]
end

it "methods don't swallow up default completion" do
Expand Down
6 changes: 3 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ def complete(*args, &block)
Bond.complete(*args, &block)
end

def valid_readline_plugin
def valid_readline
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
M.debrief :readline => TestHelpers.valid_readline
end
end

Expand All @@ -65,5 +65,5 @@ class Bacon::Context
end

# Default settings
Bond::M.debrief(:readline_plugin=>TestHelpers.valid_readline_plugin, :debug=>true)
Bond::M.debrief(:readline=>TestHelpers.valid_readline, :debug=>true)
include Bond

0 comments on commit 85ceedc

Please sign in to comment.