Class: Gem::Web::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/gem/web/executor.rb

Instance Method Summary collapse

Instance Method Details

#find_github(gem) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/gem/web/executor.rb', line 30

def find_github(gem)
  unless (meta = (gem)).nil?
    links = [meta["source_code_uri"], meta["documentation_uri"], meta["homepage_uri"]]
    uri = links.find do |link|
      !link.nil? && link.match(/http(s?):\/\/(www\.)?github.com\/.*/i)
    end
    launch_browser(gem, uri)
  end
end

#find_page(gem, page) ⇒ Object



25
26
27
28
# File 'lib/gem/web/executor.rb', line 25

def find_page(gem, page)
  meta = (gem)
  launch_browser(gem, meta[page]) unless meta.nil?
end

#get_api_metadata(gem) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/gem/web/executor.rb', line 40

def (gem)
  begin
    JSON.parse(open("https://rubygems.org/api/v1/gems/#{gem}.json").read)
  rescue OpenURI::HTTPError => ex
    puts "Did not find #{gem} on rubygems.org"
    nil
  end
end

#launch_browser(gem, uri) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/gem/web/executor.rb', line 49

def launch_browser(gem, uri)
  if uri.nil? || uri.empty?
    puts "Did not find page for #{gem}, opening RubyGems page instead."
    uri = "https://rubygems.org/gems/#{gem}"
  end

  Launchy.open(uri)
end

#open_page(gem, options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gem/web/executor.rb', line 9

def open_page(gem, options)
  if options[:sourcecode]
    find_page(gem, "source_code_uri")
  elsif options[:doc]
    find_page(gem, "documentation_uri")
  elsif options[:webpage]
    find_page(gem, "homepage_uri")
  elsif options[:rubygems]
    open_rubygems(gem)
  elsif options[:rubytoolbox]
    open_rubytoolbox(gem)
  else
    find_github(gem)
  end
end

#open_rubygems(gem) ⇒ Object



58
59
60
# File 'lib/gem/web/executor.rb', line 58

def open_rubygems(gem)
  Launchy.open("https://rubygems.org/gems/#{gem}")
end

#open_rubytoolbox(gem) ⇒ Object



62
63
64
# File 'lib/gem/web/executor.rb', line 62

def open_rubytoolbox(gem)
  Launchy.open("https://www.ruby-toolbox.com/projects/#{gem}")
end