Class: Bundler::AsOf::InstallModifier

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/as_of.rb

Instance Method Summary collapse

Constructor Details

#initializeInstallModifier

Returns a new instance of InstallModifier.



13
14
15
# File 'lib/bundler/as_of.rb', line 13

def initialize
  @modified_dependencies = {} # name => modified Bundler::Dependency
end

Instance Method Details

#as_of_dateObject



64
65
66
67
68
69
70
71
72
# File 'lib/bundler/as_of.rb', line 64

def as_of_date
  return nil if as_of_env.nil?

  @as_of_date ||= begin
    Date.parse(as_of_env)
  rescue Date::Error
    raise(BundlerError, "ERROR: bundler-as_of could not parse #{BUNDLE_AS_OF}=#{as_of_env.inspect}")
  end
end

#as_of_envObject



74
75
76
# File 'lib/bundler/as_of.rb', line 74

def as_of_env
  ENV[BUNDLE_AS_OF]
end

#modify_dependencies(dependencies) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bundler/as_of.rb', line 17

def modify_dependencies(dependencies)
  if as_of_date.nil?
    warn("NOTE: bundler-as_of is installed but #{BUNDLE_AS_OF} is not set")
    return
  end
  warn("NOTE: bundler-as_of: bundling dependencies as of #{as_of_date} ...")

  resolve_transitive_dependencies(dependencies)

  dependencies.clear
  @modified_dependencies.each do |name, dep|
    dependencies << dep
  end
end

#resolve_transitive_dependencies(dependencies) ⇒ Object



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
# File 'lib/bundler/as_of.rb', line 32

def resolve_transitive_dependencies(dependencies)
  queued = dependencies.dup

  while !queued.empty?
    resolving = queued
    queued = []

    resolving.each do |dependency|
      if dependency.name == "bundler"
        raise(BundlerError, "ERROR: please remove bundler from the Gemfile or gemspec")
      end

      next if @modified_dependencies.key?(dependency.name)

      orig_req = dependency.requirements_list
      release = VersionFinder.new(dependency, as_of_date).resolve
      if release
        warn("NOTE: bundler-as_of: resolving #{dependency.name} #{orig_req} to #{release.version} released on #{release.date}")
        @modified_dependencies[release.name] = Bundler::Dependency.new(release.name, release.version)

        release.dependencies.each do |transitive_name, transitive_req|
          transitive_dep = Gem::Dependency.new(transitive_name, transitive_req.split(","))
          queued << transitive_dep
        end
      else
        warn("NOTE: bundler-as_of: WARNING: could not resolve #{dependency.name} to a version matching #{dependency.requirements_list} from #{as_of_date}")
        @modified_dependencies[dependency.name] = dependency
      end
    end
  end
end