class Gemnasium::Parser::Gemfile

Attributes

content[R]

Public Class Methods

new(content) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 9
def initialize(content)
  @content = content
end

Public Instance Methods

dependencies() click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 13
def dependencies
  @dependencies ||= [].tap do |deps|
    gem_matches.each do |match|
      dep = dependency(match)
      deps << dep if dep
    end
  end
end
gemspec() click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 22
def gemspec
  @gemspec = if gemspec_match
    opts = Patterns.options(gemspec_match["opts"])
    path = opts["path"]
    name = opts["name"] || "*"
    File.join(*[path, "#{name}.gemspec"].compact)
  end
end
gemspec?() click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 31
def gemspec?
  !!gemspec
end

Private Instance Methods

clean!(match, opts) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 100
def clean!(match, opts)
  opts["group"] ||= opts.delete("groups")
  opts["group"] ||= groups(match)
  groups = Array(opts["group"]).flatten.compact
  runtime = groups.empty? || !(groups & Parser.runtime_groups).empty?
  opts["type"] ||= runtime ? :runtime : :development
end
dependency(match) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 44
def dependency(match)
  opts = Patterns.options(match["opts"])
  return nil if exclude?(match, opts)
  clean!(match, opts)
  name, reqs = match["name"], [match["req1"], match["req2"]].compact
  Bundler::Dependency.new(name, reqs, opts).tap do |dep|
    line = content.slice(0, match.begin(0)).count("\n") + 1
    dep.instance_variable_set(:@line, line)
  end
end
exclude?(match, opts) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 68
def exclude?(match, opts)
  git?(match, opts) || github?(match, opts) || path?(match, opts)
end
gem_matches() click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 36
def gem_matches
  @gem_matches ||= matches(Patterns::GEM_CALL)
end
gemspec_match() click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 108
def gemspec_match
  return @gemspec_match if defined?(@gemspec_match)
  @gemspec_match = content.match(Patterns::GEMSPEC_CALL)
end
git?(match, opts) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 72
def git?(match, opts)
  opts["git"] || in_git_block?(match)
end
git_matches() click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 84
def git_matches
  @git_matches ||= matches(Patterns::GIT_CALL)
end
github?(match, opts) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 76
def github?(match, opts)
  opts["github"]
end
group_matches() click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 64
def group_matches
  @group_matches ||= matches(Patterns::GROUP_CALL)
end
groups(match) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 55
def groups(match)
  group = group_matches.detect{|m| in_block?(match, m) }
  group && Patterns.values(group[:grps])
end
in_block?(inner, outer) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 60
def in_block?(inner, outer)
  outer.begin(:blk) <= inner.begin(0) && outer.end(:blk) >= inner.end(0)
end
in_git_block?(match) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 80
def in_git_block?(match)
  git_matches.any?{|m| in_block?(match, m) }
end
in_path_block?(match) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 92
def in_path_block?(match)
  path_matches.any?{|m| in_block?(match, m) }
end
matches(pattern) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 40
def matches(pattern)
  [].tap{|m| content.scan(pattern){ m << Regexp.last_match } }
end
path?(match, opts) click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 88
def path?(match, opts)
  opts["path"] || in_path_block?(match)
end
path_matches() click to toggle source
# File lib/gemnasium/parser/gemfile.rb, line 96
def path_matches
  @path_matches ||= matches(Patterns::PATH_CALL)
end