Navigation Menu

Skip to content

Commit

Permalink
:readline_plugin can take a symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed Jan 10, 2011
1 parent f6e8d73 commit 3bd58d4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/bond.rb
Expand Up @@ -91,8 +91,9 @@ 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] :readline_plugin (Bond::Readline) Specifies a Bond plugin to interface with a Readline-like
# library. Available plugins are Bond::Readline and Bond::Rawline.
# @option options [Module, Symbol] :readline_plugin (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.
# See {Agent#default_mission}.
# @option options [Symbol] :default_search (:underscore) Name of a *_search method in Rc to use as the default
Expand Down
7 changes: 6 additions & 1 deletion lib/bond/m.rb
Expand Up @@ -48,8 +48,13 @@ def spy(input)
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)
end
unless %w{setup line_buffer}.all? {|e| config[:readline_plugin].respond_to?(e) }
$stderr.puts "Bond Error: Invalid readline plugin given."
$stderr.puts "Bond Error: Invalid readline plugin '#{config[:readline_plugin]}'."
end
end

Expand Down
11 changes: 11 additions & 0 deletions test/bond_test.rb
Expand Up @@ -13,10 +13,21 @@ def start(options={}, &block)
}.should =~ /Invalid/
end

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

it "prints no error if valid readline_plugin" 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
end

it "sets default mission" do
start :default_mission=>lambda {|e| %w{1 2 3}}
tab('1').should == ['1']
Expand Down

0 comments on commit 3bd58d4

Please sign in to comment.