Class: Chef::Taste::DependencyChecker
- Inherits:
-
Object
- Object
- Chef::Taste::DependencyChecker
- Defined in:
- lib/chef/taste/dependency_checker.rb
Overview
The class checks for cookbook dependencies and populates all fields for the dependent cookbook
Class Method Summary collapse
-
.check(path = Dir.pwd) ⇒ Array<Dependency>
Check for cookbook dependencies and their versions.
-
.cookbook_exists?(name) ⇒ Boolean
Checks if a particular cookbook exists in the community site.
-
.populate_fields(dependencies) ⇒ Array<Dependency>
Populate various fields for all dependencies.
Class Method Details
.check(path = Dir.pwd) ⇒ Array<Dependency>
Check for cookbook dependencies and their versions
42 43 44 45 46 47 48 49 50 |
# File 'lib/chef/taste/dependency_checker.rb', line 42 def check(path = Dir.pwd) raise NotACookbookError, "Path is not a cookbook" unless File.exists?(File.join(path, 'metadata.rb')) ridley = Ridley::Chef::Cookbook::Metadata.from_file(File.join(path, 'metadata.rb')) dependencies = ridley.dependencies.map do |name, version| Dependency.new(name, version) end populate_fields(dependencies) end |
.cookbook_exists?(name) ⇒ Boolean
Checks if a particular cookbook exists in the community site
88 89 90 91 |
# File 'lib/chef/taste/dependency_checker.rb', line 88 def cookbook_exists?(name) rest = Berkshelf::CommunityREST.new rest.get(name).status == 200 end |
.populate_fields(dependencies) ⇒ Array<Dependency>
Populate various fields for all dependencies
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/chef/taste/dependency_checker.rb', line 58 def populate_fields(dependencies) rest = Berkshelf::CommunityREST.new dependencies.each do |dep| # Skip cookbooks that are not available in the community site. It might be an external cookbook. # next unless cookbook_exists?(dep.name) dep.latest = rest.latest_version(dep.name) # Obtain the version used based on the version constraint # dep.version_used = rest.satisfy(dep.name, dep.requirement) dep.source_url = rest.get(dep.name).body['external_url'] # Calculate the status based on the version being used and the latest version # if Solve::Version.new(dep.version_used).eql?(Solve::Version.new(dep.latest)) dep.status = TICK_MARK else dep.status = X_MARK dep.changelog = Changelog.compute(dep) end end end |