class Berkshelf::Lockfile::Graph
The class representing an internal graph.
def add(name, version)
-
(GraphItem)
-
Parameters:
-
version
(#to_s
) -- -
name
(#to_s
) --
def add(name, version) @graph[name.to_s] = GraphItem.new(name, version) end
def dependency?(dependency, options = {})
(**options)
-
:ignore
(String, Array
) --
Parameters:
-
dependency
(Dependency, String
) --
def dependency?(dependency, options = {}) name = Dependency.name(dependency) ignore = Hash[*Array(options[:ignore]).map { |i| [i, true] }.flatten] @graph.values.each do |item| next if ignore[item.name] if item.dependencies.key?(name) return true end end false end
def each(&block)
- Yield: - Hash
def each(&block) @graph.values.each(&block) end
def find(dependency)
-
(GraphItem, nil)
-
Parameters:
-
(
Dependency, String
) --
def find(dependency) @graph[Dependency.name(dependency)] end
def initialize(lockfile)
-
(Graph)
-
def initialize(lockfile) @lockfile = lockfile @berksfile = lockfile.berksfile @graph = {} end
def lock?(dependency)
-
(true, false)
-
Parameters:
-
(
Dependency, String
) --
def lock?(dependency) !find(dependency).nil? end
def locks
-
(Hash
-)
def locks @graph.sort.inject({}) do |hash, (name, item)| dependency = @lockfile.find(name) || @berksfile && @berksfile.find(name) || Dependency.new(@berksfile, name) # We need to make a copy of the dependency, or else we could be # modifying an existing object that other processes depend on! dependency = dependency.dup dependency.locked_version = item.version unless dependency.locked_version hash[item.name] = dependency hash end end
def remove(dependency, options = {})
(**options)
-
:ignore
(String, Array
) --
Parameters:
-
dependency
(Dependency, String
) --
def remove(dependency, options = {}) name = Dependency.name(dependency) if @lockfile.dependency?(name) return end if dependency?(name, options) return end # Grab the nested dependencies for this particular entry so we can # recurse and try to remove them from the graph. locked = @graph[name] nested_dependencies = locked && locked.dependencies.keys || [] # Now delete the entry @graph.delete(name) # Recursively try to delete the remaining dependencies for this item nested_dependencies.each(&method(:remove)) end
def to_lock
-
(String)
-
Other tags:
- Example: lockfile.graph.to_lock #=> "GRAPH\n apache2 (1.18.14)\n..." -
def to_lock out = "#{Lockfile::GRAPH}\n" @graph.sort.each do |name, item| out << " #{name} (#{item.version})\n" unless item.dependencies.empty? item.dependencies.sort.each do |dep_name, constraint| out << " #{dep_name} (#{constraint})\n" end end end out end
def update(cookbooks)
-
(
Array
) --
def update(cookbooks) @graph = {} cookbooks.each do |cookbook| @graph[cookbook.cookbook_name.to_s] = GraphItem.new( cookbook.cookbook_name, cookbook.version, cookbook.dependencies ) end end