Class: Berkshelf::Lockfile::Graph::GraphItem

Inherits:
Object
  • Object
show all
Defined in:
lib/berkshelf/lockfile.rb

Overview

A single item inside the graph.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, version, dependencies = {}) ⇒ GraphItem

Create a new graph item.



805
806
807
808
809
# File 'lib/berkshelf/lockfile.rb', line 805

def initialize(name, version, dependencies = {})
  @name         = name.to_s
  @version      = version.to_s
  @dependencies = dependencies
end

Instance Attribute Details

#dependenciesHash<String, String> (readonly)

The list of dependencies and their constraints.

Returns:

  • (Hash<String, String>)

    the list of dependencies for this graph item, where the key corresponds to the name of the dependency and the value is the version constraint.



802
803
804
# File 'lib/berkshelf/lockfile.rb', line 802

def dependencies
  @dependencies
end

#nameString (readonly)

The name of the cookbook that corresponds to this graph item.

Returns:

  • (String)

    the name of the cookbook



788
789
790
# File 'lib/berkshelf/lockfile.rb', line 788

def name
  @name
end

#versionString (readonly)

The locked version for this graph item.

Returns:

  • (String)

    the locked version of the graph item (as a string)



794
795
796
# File 'lib/berkshelf/lockfile.rb', line 794

def version
  @version
end

Instance Method Details

#add_dependency(name, constraint) ⇒ Object

Add a new dependency to the list.

Parameters:

  • name (#to_s)

    the name to use

  • constraint (#to_s)

    the version constraint to use



817
818
819
# File 'lib/berkshelf/lockfile.rb', line 817

def add_dependency(name, constraint)
  @dependencies[name.to_s] = constraint.to_s
end

#set_dependencies(dependencies) ⇒ Object



821
822
823
# File 'lib/berkshelf/lockfile.rb', line 821

def set_dependencies(dependencies)
  @dependencies = dependencies.to_hash
end

#to_sObject



826
827
828
# File 'lib/berkshelf/lockfile.rb', line 826

def to_s
  "#{name} (#{version})"
end