This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
/
environment.rb
83 lines (66 loc) · 1.48 KB
/
environment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
require 'erb'
module Bundler
class Environment
attr_reader :root
def initialize(root, definition)
@root = root
@definition = definition
end
# TODO: Remove this method. It's used in cli.rb still
def index
@definition.index
end
def requested_specs
@requested_specs ||= begin
groups = @definition.groups - Bundler.settings.without
groups.map! { |g| g.to_sym }
specs_for(groups)
end
end
def specs
@definition.specs
end
def dependencies
@definition.dependencies
end
def lock
write_yml_lock
end
def update(*gems)
# Nothing
end
private
def specs_for(groups)
deps = dependencies.select { |d| (d.groups & groups).any? }
specs.for(deps)
end
# ==== Locking
def write_yml_lock
File.open("#{root}/Gemfile.lock", 'w') do |f|
f.puts lock_content
end
end
def lock_content
out = ""
@definition.sources.each do |source|
# Add the source header
out << source.to_lock
# Find all specs for this source
specs.
select { |s| s.source == source }.
sort_by { |s| s.name }.
each do |spec|
out << spec.to_lock
end
out << "\n"
end
out << "DEPENDENCIES\n"
@definition.dependencies.
sort_by { |d| d.name }.
each do |dep|
out << dep.to_lock
end
out
end
end
end