class RustLang

Constants

API_URL
CARGOFILE_SECTIONS

Public Class Methods

latest_version(name) click to toggle source

Find the latest versions of a dependency by name

name - String name of the dependency

Returns a Gem::Version

# File lib/cutting_edge/langs/rust.rb, line 43
def latest_version(name)
  begin
    content = HTTP.timeout(::CuttingEdge::LAST_VERSION_TIMEOUT).get(::File.join(API_URL, name)).parse
    version = content['crate']['max_version']
    Gem::Version.new(canonical_version(version))
  rescue StandardError, HTTP::Error => e
    log_error("Encountered error when fetching latest version of #{name}: #{e.class} #{e.message}")
    nil
  end      
end
locations(name = nil) click to toggle source

Defaults for projects in this language

# File lib/cutting_edge/langs/rust.rb, line 18
def locations(name = nil)
  ['Cargo.toml']
end
parse_file(name, content) click to toggle source

Parse a dependency file

name - String contents of the file content - String contents of the file

Returns an Array of tuples of each dependency and its latest version: [[<Gem::Dependency>, <Gem::Version>]]

# File lib/cutting_edge/langs/rust.rb, line 32
def parse_file(name, content)
  return nil unless content
  results = parse_toml(content, CARGOFILE_SECTIONS)
  dependency_with_latest(results) if results
end
translate_requirement(req) click to toggle source

Translate Cargo version requirement syntax to a String or Array of Strings that Gem::Dependency.new understands Cargo.toml files support * and ^ (wildcard and caret) requirements, which Ruby does not See: doc.rust-lang.org/cargo/reference/specifying-dependencies.html

req - String version requirement

Returns a translated String version requirement

# File lib/cutting_edge/langs/rust.rb, line 61
def translate_requirement(req)
  if req =~ /~|<|>|\*|=/
    return translate_wildcard(req) if req =~ /\*/
    req.sub!('~', '~>')
    req
  else
    translate_caret(req)
  end
end
website(name) click to toggle source
# File lib/cutting_edge/langs/rust.rb, line 22
def website(name)
  "https://crates.io/crates/#{name}"
end