Skip to content

Commit

Permalink
Bond.load_yard_gems
Browse files Browse the repository at this point in the history
  • Loading branch information
cldwalker committed May 17, 2010
1 parent df11d0f commit a31e55b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
14 changes: 11 additions & 3 deletions lib/bond.rb
Expand Up @@ -12,6 +12,7 @@
require 'bond/missions/object_mission'
require 'bond/missions/anywhere_mission'
require 'bond/missions/operator_method_mission'
require 'bond/yard'

module Bond
extend self
Expand Down Expand Up @@ -75,10 +76,11 @@ def spy(*args); M.spy(*args); end
def config; M.config; end

# Starts Bond with a default set of completions that replace and improve irb's completion. Loads completions
# in this order: lib/bond/completion.rb, lib/bond/completions/*.rb and the following optional
# completions: gem completions from :gems, ~/.bondrc, ~/.bond/completions/*.rb and from block. See Rc for
# the DSL to use in completion files and in the block. Valid options are Bond.config keys and the following:
# in this order: lib/bond/completion.rb, lib/bond/completions/*.rb and the following optional completions:
# completions from :gems, completions from :yard_gems, ~/.bondrc, ~/.bond/completions/*.rb and from block. See
# Rc for the DSL to use in completion files and in the block. Valid options are Bond.config keys and the following:
# [*:gems*] Array of gems which have their completions loaded from lib/bond/completions/#{gem}.rb.
# [*:yard_gems*] Array of gems using yard documentation to generate completions. See Yard.
# ==== Examples:
# Bond.start :gems=>%w{hirb}
# Bond.start(:default_search=>:ignore_case) do
Expand All @@ -89,6 +91,12 @@ def start(options={}, &block); M.start(options, &block); end
# Loads completions for gems that ship with them at lib/bond/completions/#{gem}.rb.
def load_gems(*gems); M.load_gems(*gems); end

# Generates and loads completions for yardoc documented gems.
# ==== Options:
# [*:verbose*] Boolean which displays additional information when building yardoc. Default is false.
# [*:reload*] Rebuilds yard databases. Use when gems have changed versions. Default is false.
def load_yard_gems(*gems); Yard.load_yard_gems(*gems); end

# An Agent who saves all Bond.complete missions and executes the correct one when a completion is called.
def agent; M.agent; end

Expand Down
3 changes: 2 additions & 1 deletion lib/bond/m.rb
Expand Up @@ -80,7 +80,8 @@ def load_gems(*gems) #:nodoc:
def load_completions #:nodoc:
load_file File.join(File.dirname(__FILE__), 'completion.rb')
load_dir File.dirname(__FILE__)
load_gems *Array(config[:gems])
load_gems *config[:gems] if config[:gems]
Yard.load_yard_gems *config[:yard_gems] if config[:yard_gems]
load_file(File.join(home,'.bondrc')) if File.exists?(File.join(home, '.bondrc'))
load_dir File.join(home, '.bond')
end
Expand Down
12 changes: 9 additions & 3 deletions lib/bond/yard.rb
@@ -1,12 +1,15 @@
module Bond
# Generates method autocompletions for gems that use {yard}[http://yardoc.org] documentation. Currently
# generates completions for methods that take a hash of options and have been documented with @option.
module Yard
extend self

# :stopdoc:
def load_yard_gems(*gems)
@options = gems[-1].is_a?(Hash) ? gems.pop : {}
require 'yard'
raise LoadError unless YARD::VERSION >= '0.5.2'
gems.each {|e| load_yard_gem(e) }
gems.select {|e| load_yard_gem(e) }
rescue LoadError
$stderr.puts "Bond Error: yard gem (version >= 0.5.2) not installed "
end
Expand All @@ -29,10 +32,12 @@ def find_yardoc(rubygem)
(file = YARD::Registry.yardoc_file_for_gem(rubygem) rescue nil) and return(file)
if (file = M.find_gem_file(rubygem, rubygem+'.rb'))
output_dir = File.join(dir('.yardocs'), rubygem)
cmd = ['yardoc', '-nq', '-b', output_dir]
cmd = ['yardoc', '-n', '-b', output_dir]
cmd << '-q' unless @options[:verbose]
cmd += ['-c', output_dir] unless @options[:reload]
cmd += [file, File.expand_path(file+'/..')+"/#{rubygem}/**/*.rb"]
puts cmd.join(' '), "Building #{rubygem}'s YARD database ..."
puts cmd.join(' ') if @options[:verbose]
puts "Building #{rubygem}'s .yardoc database ..."
system *cmd
output_dir
end
Expand All @@ -58,5 +63,6 @@ def generate_method_completions(methods_hash)
%Q[complete(:method=>'#{meth}') {\n #{options.inspect}\n}]
end.join("\n")
end
#:startdoc:
end
end

0 comments on commit a31e55b

Please sign in to comment.