Skip to content

Commit

Permalink
Support only some info from metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
MatheusRich committed Aug 7, 2019
1 parent d7656a1 commit b0752dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
29 changes: 17 additions & 12 deletions lib/rubygems/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@ module Gem
module Web
class Executor

def supported_options_from_metadata
["source_code_uri", "documentation_uri"]
end

def open_page(gem, options)
spec = Gem::Specification.find_by_name(gem)

if options[:sourcecode]
source_code_uri = spec.metadata["source_code_uri"]
if source_code_uri
open_default_browser(source_code_uri)
else
puts("This gem has no info about its source code.")
end
get_info_from_metadata(spec, "source_code_uri")
elsif options[:doc]
documentation_uri = spec.metadata["documentation_uri"]
if documentation_uri
open_default_browser(documentation_uri)
else
puts("This gem has no info about its documentation.")
end
get_info_from_metadata(spec, "documentation_uri")
elsif options[:webpage]
open_default_browser(spec.homepage)
elsif options[:rubygems]
Expand All @@ -35,6 +29,17 @@ def open_page(gem, options)
puts e.message
end

def get_info_from_metadata(spec, info)
return unless supported_options_from_metadata.include?(info)

uri = spec.metadata[info]
if !uri.nil? && !uri.empty?
open_default_browser(uri)
else
puts("This gem does not have this information.")
end
end

def open_rubygems(gem)
open_default_browser("https://rubygems.org/gems/#{gem}")
end
Expand Down
9 changes: 2 additions & 7 deletions test/rubygems/test_gem_commands_web_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,10 @@ def test_open_the_source_code
end

def test_open_when_info_is_missing
[
["-c", "This gem has no info about its source code.\n"],
["-d", "This gem has no info about its documentation.\n"],
].each do |test_case|
option = test_case[0]
error = test_case[1]
["-c", "-d"].each do |option|
@mock.expect(:metadata, {})
Gem::Specification.stub :find_by_name, @mock do
assert_output(error) do
assert_output("This gem does not have this information.\n") do
@cmd.handle_options [option, @gem]
@cmd.execute
end
Expand Down

0 comments on commit b0752dc

Please sign in to comment.