Module: Rsense::Server::LoadPath

Defined in:
lib/rsense/server/load_path.rb

Defined Under Namespace

Classes: Dependency

Class Method Summary collapse

Class Method Details

.check_version(gem_paths, version) ⇒ Object



43
44
45
46
47
# File 'lib/rsense/server/load_path.rb', line 43

def check_version(gem_paths, version)
  gem_paths.select do |p|
    p.to_s =~ /#{version}/
  end
end

.dependencies(project) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rsense/server/load_path.rb', line 19

def dependencies(project)
  @deps = []
  @gemfile = find_gemfile(project)
  if @gemfile
    start_dir = Dir.pwd
    Dir.chdir(@gemfile.dirname)
    lockfile = Bundler::LockfileParser.new(Bundler.read_file(@gemfile))
    @deps = gem_info(lockfile)
    Dir.chdir(start_dir)
  end
  @deps
end

.fetchObject



15
16
17
# File 'lib/rsense/server/load_path.rb', line 15

def fetch
  $LOAD_PATH
end

.find_gemfile(project, level = 0) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rsense/server/load_path.rb', line 55

def find_gemfile(project, level=0)
  level = level + 1
  pth = Pathname.new(project).expand_path
  lockfile = pth.join("Gemfile.lock")
  if lockfile.exist?
    return lockfile
  else
    unless level > 6
      lockfile = find_gemfile(pth.parent, level)
    end
  end
end

.find_paths(name) ⇒ Object



49
50
51
52
53
# File 'lib/rsense/server/load_path.rb', line 49

def find_paths(name)
  paths = Gem.find_files(name)
  return paths unless paths.empty? && name.length > 1
  find_paths(name.chop)
end

.gem_info(lfile) ⇒ Object



32
33
34
35
36
# File 'lib/rsense/server/load_path.rb', line 32

def gem_info(lfile)
  lfile.specs.map do |s|
    generate_struct(s.name, s.version)
  end
end

.generate_struct(name, version) ⇒ Object



38
39
40
41
# File 'lib/rsense/server/load_path.rb', line 38

def generate_struct(name, version)
  paths = check_version(find_paths(name), version)
  Dependency.new(name, "#{name}-#{version.to_s}", paths)
end

.pathsObject



11
12
13
# File 'lib/rsense/server/load_path.rb', line 11

def paths
  fetch.map { |p| p unless p.to_s =~ /^file:/ }
end