Class: Berkshelf::Dependency
- Inherits:
-
Object
- Object
- Berkshelf::Dependency
- Defined in:
- lib/berkshelf/dependency.rb
Instance Attribute Summary collapse
- #berksfile ⇒ Berkshelf::Berksfile readonly
-
#groups ⇒ Array<Symbol>
The list of groups this dependency belongs to.
- #location ⇒ Berkshelf::Location readonly
- #locked_version ⇒ Semverse::Version
- #name ⇒ String readonly
- #source ⇒ Source
- #version_constraint ⇒ Semverse::Constraint
Class Method Summary collapse
-
.name(dependency) ⇒ String
Returns the name of this cookbook (because it’s the key in hash tables).
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #add_group(*local_groups) ⇒ Object
-
#cached_cookbook ⇒ CachedCookbook?
Attempt to load the cached_cookbook for this dependency.
-
#has_group?(group) ⇒ Boolean
Returns true if this dependency has the given group.
-
#initialize(berksfile, name, options = {}) ⇒ Dependency
constructor
A new instance of Dependency.
- #inspect ⇒ Object
-
#installed? ⇒ Boolean
Determine if this dependency is installed.
-
#metadata? ⇒ Boolean
Return true if this is a metadata location.
- #to_lock ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(berksfile, name, options = {}) ⇒ Dependency
Returns a new instance of Dependency.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/berkshelf/dependency.rb', line 57 def initialize(berksfile, name, = {}) @options = @berksfile = berksfile @name = name @metadata = [:metadata] @location = Location.init(self, ) if [:locked_version] @locked_version = Semverse::Version.coerce([:locked_version]) end # The coerce method automatically gives us a default constraint of # >= 0.0.0 if the constraint is not set. @version_constraint = Semverse::Constraint.coerce([:constraint]) add_group([:group]) if [:group] add_group(:default) if groups.empty? end |
Instance Attribute Details
#berksfile ⇒ Berkshelf::Berksfile (readonly)
21 22 23 |
# File 'lib/berkshelf/dependency.rb', line 21 def berksfile @berksfile end |
#groups ⇒ Array<Symbol>
The list of groups this dependency belongs to.
157 158 159 |
# File 'lib/berkshelf/dependency.rb', line 157 def groups @groups ||= [] end |
#location ⇒ Berkshelf::Location (readonly)
27 28 29 |
# File 'lib/berkshelf/dependency.rb', line 27 def location @location end |
#locked_version ⇒ Semverse::Version
29 30 31 |
# File 'lib/berkshelf/dependency.rb', line 29 def locked_version @locked_version end |
#version_constraint ⇒ Semverse::Constraint
31 32 33 |
# File 'lib/berkshelf/dependency.rb', line 31 def version_constraint @version_constraint end |
Class Method Details
.name(dependency) ⇒ String
Returns the name of this cookbook (because it’s the key in hash tables).
11 12 13 14 15 16 17 |
# File 'lib/berkshelf/dependency.rb', line 11 def name(dependency) if dependency.is_a?(Dependency) dependency.name.to_s else dependency.to_s end end |
Instance Method Details
#<=>(other) ⇒ Object
161 162 163 |
# File 'lib/berkshelf/dependency.rb', line 161 def <=>(other) [name, version_constraint] <=> [other.name, other.version_constraint] end |
#add_group(*local_groups) ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/berkshelf/dependency.rb', line 99 def add_group(*local_groups) local_groups = local_groups.first if local_groups.first.is_a?(Array) local_groups.each do |group| group = group.to_sym groups << group unless groups.include?(group) end end |
#cached_cookbook ⇒ CachedCookbook?
Attempt to load the cached_cookbook for this dependency. For SCM/path locations, this method delegates to BaseLocation#cached_cookbook. For generic dependencies, this method tries attemps to load a matching cookbook from the CookbookStore.
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/berkshelf/dependency.rb', line 122 def cached_cookbook return @cached_cookbook if @cached_cookbook @cached_cookbook = if location cookbook = location.cached_cookbook # If we have a cached cookbook, tighten our constraints if cookbook self.locked_version = cookbook.version self.version_constraint = cookbook.version end cookbook else if locked_version CookbookStore.instance.cookbook(name, locked_version) else CookbookStore.instance.satisfy(name, version_constraint) end end @cached_cookbook end |
#has_group?(group) ⇒ Boolean
Returns true if this dependency has the given group.
150 151 152 |
# File 'lib/berkshelf/dependency.rb', line 150 def has_group?(group) groups.include?(group.to_sym) end |
#inspect ⇒ Object
169 170 171 172 173 174 175 176 |
# File 'lib/berkshelf/dependency.rb', line 169 def inspect "#<Berkshelf::Dependency: " << [ "#{name} (#{version_constraint})", "locked_version: #{locked_version.inspect}", "groups: #{groups}", "location: #{location || "default"}>", ].join(", ") end |
#installed? ⇒ Boolean
Determine if this dependency is installed. A dependency is “installed” if the associated CachedCookbook exists on disk.
112 113 114 |
# File 'lib/berkshelf/dependency.rb', line 112 def installed? !cached_cookbook.nil? end |
#metadata? ⇒ Boolean
Return true if this is a metadata location.
79 80 81 |
# File 'lib/berkshelf/dependency.rb', line 79 def !!@metadata end |
#to_lock ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/berkshelf/dependency.rb', line 178 def to_lock out = if location || version_constraint.to_s == ">= 0.0.0" " #{name}\n" else " #{name} (#{version_constraint})\n" end out << location.to_lock if location out end |
#to_s ⇒ Object
165 166 167 |
# File 'lib/berkshelf/dependency.rb', line 165 def to_s "#{name} (#{locked_version || version_constraint})" end |