Class: Vagrant::Bundler::SolutionFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin_file:, solution_file: nil) ⇒ SolutionFile

Returns a new instance of SolutionFile.

Parameters:

  • plugin_file (Pathname)

    Path to plugin file

  • solution_file (Pathname) (defaults to: nil)

    Custom path to solution file


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vagrant/bundler.rb', line 31

def initialize(plugin_file:, solution_file: nil)
  @logger = Log4r::Logger.new("vagrant::bundler::solution_file")
  @plugin_file = Pathname.new(plugin_file.to_s)
  if solution_file
    @solution_file = Pathname.new(solution_file.to_s)
  else
    @solution_file = Pathname.new(@plugin_file.to_s + ".sol")
  end
  @valid = false
  @dependency_list = [].freeze
  @logger.debug("new solution file instance plugin_file=#{plugin_file} " \
    "solution_file=#{solution_file}")
  load
end

Instance Attribute Details

#dependency_listArray<Gem::Resolver::DependencyRequest>

Returns list of required dependencies.

Returns:

  • (Array<Gem::Resolver::DependencyRequest>)

    list of required dependencies


27
28
29
# File 'lib/vagrant/bundler.rb', line 27

def dependency_list
  @dependency_list
end

#plugin_filePathname (readonly)

Returns path to plugin file.

Returns:

  • (Pathname)

    path to plugin file


23
24
25
# File 'lib/vagrant/bundler.rb', line 23

def plugin_file
  @plugin_file
end

#solution_filePathname (readonly)

Returns path to solution file.

Returns:

  • (Pathname)

    path to solution file


25
26
27
# File 'lib/vagrant/bundler.rb', line 25

def solution_file
  @solution_file
end

Instance Method Details

#delete!Boolean

Delete the solution file

Returns:

  • (Boolean)

    true if file was deleted


76
77
78
79
80
81
82
83
84
# File 'lib/vagrant/bundler.rb', line 76

def delete!
  if !solution_file.exist?
    @logger.debug("solution file does not exist. nothing to delete.")
    return false
  end
  @logger.debug("deleting solution file - #{solution_file}")
  solution_file.delete
  true
end

#invalidate!FalseClass

Returns invalidate this solution file.

Returns:

  • (FalseClass)

    invalidate this solution file


67
68
69
70
71
# File 'lib/vagrant/bundler.rb', line 67

def invalidate!
  @valid = false
  @logger.debug("manually invalidating solution file #{self}")
  @valid
end

#store!Object

Store the solution file


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/vagrant/bundler.rb', line 87

def store!
  if !plugin_file.exist?
    @logger.debug("plugin file does not exist, not storing solution")
    return
  end
  if !solution_file.dirname.exist?
    @logger.debug("creating directory for solution file: #{solution_file.dirname}")
    solution_file.dirname.mkpath
  end
  @logger.debug("writing solution file contents to disk")
  solution_file.write({
    dependencies: dependency_list.map { |d|
      [d.dependency.name, d.dependency.requirements_list]
    },
    checksum: plugin_file_checksum,
    vagrant_version: Vagrant::VERSION
  }.to_json)
  @valid = true
end

#to_sObject

:nodoc:


107
108
109
110
# File 'lib/vagrant/bundler.rb', line 107

def to_s # :nodoc:
  "<Vagrant::Bundler::SolutionFile:#{plugin_file}:" \
    "#{solution_file}:#{valid? ? "valid" : "invalid"}>"
end

#valid?Boolean

Returns contained solution is valid.

Returns:

  • (Boolean)

    contained solution is valid


62
63
64
# File 'lib/vagrant/bundler.rb', line 62

def valid?
  @valid
end