Class: RubyLang

Inherits:
Language show all
Defined in:
lib/cutting_edge/langs/ruby.rb

Class Method Summary collapse

Methods inherited from Language

#website

Methods included from LanguageHelpers

#dependency_with_latest, #log_error, #unknown_dependency

Class Method Details

.latest_version(name) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/cutting_edge/langs/ruby.rb', line 29

def latest_version(name)
  # Fancy todo: cache these?
  begin
    Gem::SpecFetcher.fetcher.spec_for_dependency(Gem::Dependency.new(name, nil)).flatten.first.version
  rescue StandardError => e
    log_error("Encountered error when fetching latest version of #{name}: #{e.class} #{e.message}")
    nil
  end
end

.locations(name) ⇒ Object

Defaults for projects in this language



9
10
11
# File 'lib/cutting_edge/langs/ruby.rb', line 9

def locations(name)
  ["#{name}.gemspec", 'Gemfile']
end

.parse_file(name, content) ⇒ Object

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: [[<Bundler::Dependency>, <Gem::Version>]]



23
24
25
26
27
# File 'lib/cutting_edge/langs/ruby.rb', line 23

def parse_file(name, content)
  return nil unless content
  results = name =~ /gemspec/ ? parse_gemspec(content) : parse_gemfile(content)
  dependency_with_latest(results)
end

.parse_gemfile(content) ⇒ Object



47
48
49
# File 'lib/cutting_edge/langs/ruby.rb', line 47

def parse_gemfile(content)
  parse_ruby(:gemfile, content)
end

.parse_gemspec(content) ⇒ Object



43
44
45
# File 'lib/cutting_edge/langs/ruby.rb', line 43

def parse_gemspec(content)
  parse_ruby(:gemspec, content)
end

.parse_ruby(type, content) ⇒ Object



39
40
41
# File 'lib/cutting_edge/langs/ruby.rb', line 39

def parse_ruby(type, content)
  Gemnasium::Parser.send(type, content).dependencies
end

.website(name) ⇒ Object



13
14
15
# File 'lib/cutting_edge/langs/ruby.rb', line 13

def website(name)
  "https://rubygems.org/gems/#{name}"
end