Class: PuppetfileResolver::ResolutionProvider
- Inherits:
-
Object
- Object
- PuppetfileResolver::ResolutionProvider
- Includes:
- Molinillo::SpecificationProvider
- Defined in:
- lib/puppetfile-resolver/resolution_provider.rb
Instance Method Summary collapse
-
#allow_missing?(dependency) ⇒ Boolean
Returns whether this dependency, which has no possible matching specifications, can safely be ignored.
-
#dependencies_for(specification) ⇒ Array<Object>
Returns the dependencies of ‘specification`.
- #find_puppet_specifications(dependency) ⇒ Object
-
#initialize(puppetfile_document, puppet_version, resolver_ui, options = {}) ⇒ ResolutionProvider
constructor
options module_paths : Array of paths strict_mode : [Boolean] Whether missing dependencies throw an error (default: false).
-
#name_for(dependency) ⇒ String
Returns the name for the given ‘dependency`.
- #name_for_explicit_dependency_source ⇒ Object
- #name_for_locking_dependency_source ⇒ Object
-
#requirement_satisfied_by?(requirement, _activated, spec) ⇒ Boolean
Determines whether the given ‘requirement` is satisfied by the given `spec`, in the context of the current `activated` dependency graph.
-
#search_for(dependency) ⇒ Array<Object>
Search for the specifications that match the given dependency.
-
#sort_dependencies(dependencies, activated, conflicts) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument You’re drunk rubocop.
Constructor Details
#initialize(puppetfile_document, puppet_version, resolver_ui, options = {}) ⇒ ResolutionProvider
options
module_paths : Array of paths
strict_mode : [Boolean] Whether missing dependencies throw an error (default: false)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 16 def initialize(puppetfile_document, puppet_version, resolver_ui, = {}) require 'semantic_puppet' @puppetfile_document = puppetfile_document raise 'The UI object must be of type Molinillo::UI' if resolver_ui.nil? || !resolver_ui.is_a?(Molinillo::UI) @resolver_ui = resolver_ui # TODO: This default crap should move to the resolve class and we just validate (and raise) here @puppet_module_paths = [:module_paths].nil? ? [] : [:module_paths] @allow_missing_modules = [:allow_missing_modules].nil? ? true : [:allow_missing_modules] == true # There can be only one puppet specification in existance so we pre-load here. @puppet_specification = Models::PuppetSpecification.new(puppet_version) @module_info = {} @cache = [:cache].nil? ? Cache::Base.new : [:cache] end |
Instance Method Details
#allow_missing?(dependency) ⇒ Boolean
Returns whether this dependency, which has no possible matching specifications, can safely be ignored.
120 121 122 123 124 125 126 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 120 def allow_missing?(dependency) # Puppet dependencies must _always_ be resolvable return false if dependency.is_a?(Models::PuppetDependency) # Explicit Puppetfile dependencies must _always_ be resolvable return false if dependency.is_a?(Models::PuppetfileDependency) @allow_missing_modules end |
#dependencies_for(specification) ⇒ Array<Object>
This method should be ‘pure’, i.e. the return value should depend only on the ‘specification` parameter.
Returns the dependencies of ‘specification`.
70 71 72 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 70 def dependencies_for(specification) specification.dependencies(@cache, @resolver_ui) end |
#find_puppet_specifications(dependency) ⇒ Object
58 59 60 61 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 58 def find_puppet_specifications(dependency) # Puppet specifications are a bit special as there can be only one (Highlander style) dependency.satisified_by?(@puppet_specification) ? [@puppet_specification] : [] end |
#name_for(dependency) ⇒ String
This method should be ‘pure’, i.e. the return value should depend only on the ‘dependency` parameter.
Returns the name for the given ‘dependency`.
80 81 82 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 80 def name_for(dependency) dependency.name end |
#name_for_explicit_dependency_source ⇒ Object
97 98 99 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 97 def name_for_explicit_dependency_source 'Puppetfile' end |
#name_for_locking_dependency_source ⇒ Object
101 102 103 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 101 def name_for_locking_dependency_source 'Puppetfile' end |
#requirement_satisfied_by?(requirement, _activated, spec) ⇒ Boolean
Determines whether the given ‘requirement` is satisfied by the given `spec`, in the context of the current `activated` dependency graph.
93 94 95 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 93 def requirement_satisfied_by?(requirement, _activated, spec) requirement.satisified_by?(spec) end |
#search_for(dependency) ⇒ Array<Object>
This method should be ‘pure’, i.e. the return value should depend only on the ‘dependency` parameter.
Search for the specifications that match the given dependency. The specifications in the returned array will be considered in reverse order, so the latest version ought to be last.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 40 def search_for(dependency) case dependency when Models::PuppetDependency result = find_puppet_specifications(dependency) when Models::ModuleDependency result = find_all_module_specifications(dependency).select do |spec| dependency.satisified_by?(spec) end else # No idea how we got here?!?! raise ArgumentError, "Unknown Dependency type #{dependency.class}" end return result if result.empty? || result.count == 1 # Reverse sort by version result.sort! { |a, b| a.version > b.version ? 1 : -1 } end |
#sort_dependencies(dependencies, activated, conflicts) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument You’re drunk rubocop
105 106 107 108 109 110 111 112 113 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 105 def sort_dependencies(dependencies, activated, conflicts) # rubocop:disable Lint/UnusedMethodArgument You're drunk rubocop dependencies.sort_by do |dependency| name = name_for(dependency) [ activated.vertex_named(name).payload ? 0 : 1, conflicts[name] ? 0 : 1 ] end end |