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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vagrant/bundler.rb', line 34

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



30
31
32
# File 'lib/vagrant/bundler.rb', line 30

def dependency_list
  @dependency_list
end

#plugin_filePathname (readonly)

Returns path to plugin file.

Returns:

  • (Pathname)

    path to plugin file



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

def plugin_file
  @plugin_file
end

#solution_filePathname (readonly)

Returns path to solution file.

Returns:

  • (Pathname)

    path to solution file



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

def solution_file
  @solution_file
end

Instance Method Details

#delete!Boolean

Delete the solution file

Returns:

  • (Boolean)

    true if file was deleted



79
80
81
82
83
84
85
86
87
# File 'lib/vagrant/bundler.rb', line 79

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



70
71
72
73
74
# File 'lib/vagrant/bundler.rb', line 70

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

#store!Object

Store the solution file



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

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:



110
111
112
113
# File 'lib/vagrant/bundler.rb', line 110

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



65
66
67
# File 'lib/vagrant/bundler.rb', line 65

def valid?
  @valid
end