Class: RubyGemsOrg

Inherits:
Website show all
Defined in:
lib/license_auto/website/ruby_gems_org.rb

Constant Summary collapse

URI =
'https://rubygems.org/'
HOST =
'rubygems.org'
LANGUAGE =
'Ruby'
GEM_NOT_FOUND =
"This rubygem could not be found."

Instance Method Summary collapse

Methods inherited from Website

#to_s

Constructor Details

#initialize(package) ⇒ RubyGemsOrg

Returns a new instance of RubyGemsOrg.



16
17
18
# File 'lib/license_auto/website/ruby_gems_org.rb', line 16

def initialize(package)
  super(package)
end

Instance Method Details

#download_gemObject



90
91
# File 'lib/license_auto/website/ruby_gems_org.rb', line 90

def download_gem()
end

#get_gem_infoObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/license_auto/website/ruby_gems_org.rb', line 51

def get_gem_info()
  # TODO: Gems.info(@package.name, @package.version)
  gem_info = Gems.info(@package.name)
  gem_info =
      if gem_info == GEM_NOT_FOUND
        nil
      else
        Hashie::Mash.new(gem_info)
      end
end

#get_latest_version"authors" => "David Heinemeier Hansson", ...

Returns:

  • ("authors" => "David Heinemeier Hansson", "built_at" => "2016-03-07T00:00:00.000Z", "created_at" => "2016-03-07T22:33:22.563Z", "description" => "Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.", "downloads_count" => 28113, "metadata" => {}, "number" => "4.2.6", "summary" => "Full-stack web application framework.", "platform" => "ruby", "ruby_version" => ">= 1.9.3", "prerelease" => false, "licenses" => [ [0] "MIT" ], "requirements" => [], "sha" => "a199258c0d2bae09993a6932c49df254fd66428899d1823b8c5285de02e5bc33")

    “authors” => “David Heinemeier Hansson”, “built_at” => “2016-03-07T00:00:00.000Z”, “created_at” => “2016-03-07T22:33:22.563Z”, “description” => “Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.”, “downloads_count” => 28113, “metadata” => {}, “number” => “4.2.6”, “summary” => “Full-stack web application framework.”, “platform” => “ruby”, “ruby_version” => “>= 1.9.3”, “prerelease” => false, “licenses” => [

    [0] "MIT"
    

    ], “requirements” => [], “sha” => “a199258c0d2bae09993a6932c49df254fd66428899d1823b8c5285de02e5bc33”



81
82
83
84
85
86
87
88
# File 'lib/license_auto/website/ruby_gems_org.rb', line 81

def get_latest_version()
  versions = Gems.versions(@package.name).reject { |v| v['prerelease'] }.first
  if versions == GEM_NOT_FOUND
    raise(GEM_NOT_FOUND)
  end

  versions.reject { |v| v['prerelease'] }.first
end

#get_license_infoObject

(Defaults to the latest version if no version is specified.)



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/license_auto/website/ruby_gems_org.rb', line 22

def get_license_info()
  if @package.version.nil?
    begin
      @package.version = get_latest_version['number']
    rescue Exception => e
      # TODO: what returned value is better?
      return nil
    end
  end

  gem_info = get_gem_info

  raise LicenseAuto::PackageNotFound if gem_info.nil?

  source_code_matcher = LicenseAuto::Matcher::SourceURL.new(gem_info.source_code_uri)

  github_matched = source_code_matcher.match_github_resource
  if github_matched
    license_info = GithubCom.new(@package, github_matched[:owner], github_matched[:repo]).get_license_info
  elsif false

  end

  # bitbucket_matched = source_code_matcher.match_bitbucket_resource()
  # if github_matched
  #   # TODO: bitbucket_matched
  # end
end