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 (Deprecated) strict_mode : [Boolean] Whether missing dependencies throw an error (default: false) spec_searcher_configuration : PuppetfileResolver::SpecSearchers::Configuration.
-
#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 givenspec
, in the context of the currentactivated
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 (Deprecated) strict_mode : [Boolean] Whether missing dependencies throw an error (default: false) spec_searcher_configuration : PuppetfileResolver::SpecSearchers::Configuration
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 18 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 @spec_searcher_configuration = [:spec_searcher_configuration] || PuppetfileResolver::SpecSearchers::Configuration.new @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] # Check for deprecated options unless [:module_paths].nil? # rubocop:disable Style/GuardClause Warning.warn 'The use of the module_paths option has been deprecated' @spec_searcher_configuration.local.puppet_module_paths = [:module_paths] end end |
Instance Method Details
#allow_missing?(dependency) ⇒ Boolean
Returns whether this dependency, which has no possible matching specifications, can safely be ignored.
127 128 129 130 131 132 133 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 127 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
.
77 78 79 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 77 def dependencies_for(specification) specification.dependencies(@cache, @resolver_ui) end |
#find_puppet_specifications(dependency) ⇒ Object
65 66 67 68 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 65 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
.
87 88 89 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 87 def name_for(dependency) dependency.name end |
#name_for_explicit_dependency_source ⇒ Object
104 105 106 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 104 def name_for_explicit_dependency_source 'Puppetfile' end |
#name_for_locking_dependency_source ⇒ Object
108 109 110 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 108 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.
100 101 102 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 100 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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 47 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
112 113 114 115 116 117 118 119 120 |
# File 'lib/puppetfile-resolver/resolution_provider.rb', line 112 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 |