Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to restrict gems from Gemfile (deps only) #1086

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions lib/yard/cli/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,26 @@ def add_gems
end
end

def add_gems_from_gemfile(gemfile = nil)
def add_gems_from_gemfile(gemfile = nil, dependencies_only = false)
require 'bundler'
gemfile ||= "Gemfile"
if File.exist?("#{gemfile}.lock")
Bundler::LockfileParser.new(File.read("#{gemfile}.lock")).specs.each do |spec|
libraries[spec.name] ||= []
libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)]
if dependencies_only
parsed_gemfile = Bundler::LockfileParser.new(File.read("#{gemfile}.lock"))
parsed_gemfile.dependencies.each do |dep|
libraries[dep.name] ||= []
specs = parsed_gemfile.specs.select do |spec|
spec.name == dep.name
end
specs.each do |spec|
libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)]
end
end
else
Bundler::LockfileParser.new(File.read("#{gemfile}.lock")).specs.each do |spec|
libraries[spec.name] ||= []
libraries[spec.name] |= [YARD::Server::LibraryVersion.new(spec.name, spec.version.to_s, nil, :gem)]
end
end
else
log.warn "Cannot find #{gemfile}.lock, ignoring --gemfile option"
Expand Down Expand Up @@ -174,6 +187,9 @@ def optparse(*args)
opts.on('-G', '--gemfile [GEMFILE]', 'Serves documentation for gems from Gemfile') do |gemfile|
add_gems_from_gemfile(gemfile)
end
opts.on('--gemfile-deps [GEMFILE]', 'Serves documentation for gems from Gemfile (Just dependencies)') do |gemfile|
add_gems_from_gemfile(gemfile, true)
end
opts.on('-t', '--template-path PATH',
'The template path to look for templates in. (used with -t).') do |path|
template_paths << path
Expand Down