class Gem::Molinillo::VersionConflict
版本冲突引起的错误
属性
conflicts[R]
@return [{String => Resolution::Conflict}] 导致冲突的冲突项
resolution to fail
specification_provider[R]
@return [SpecificationProvider] 在期间使用的规范提供者
resolution
公共类方法
new(conflicts, specification_provider) 点击切换源代码
使用给定的版本冲突初始化新错误。 @param [{String => Resolution::Conflict}] conflicts 参见 {#conflicts} @param [SpecificationProvider] specification_provider
参见 {#specification_provider}
调用父类方法
# File rubygems/vendor/molinillo/lib/molinillo/errors.rb, line 66 def initialize(conflicts, specification_provider) pairs = [] conflicts.values.flat_map(&:requirements).each do |conflicting| conflicting.each do |source, conflict_requirements| conflict_requirements.each do |c| pairs << [c, source] end end end super "Unable to satisfy the following requirements:\n\n" \ "#{pairs.map { |r, d| "- `#{r}` required by `#{d}`" }.join("\n")}" @conflicts = conflicts @specification_provider = specification_provider end
公共实例方法
message_with_trees(opts = {}) 点击切换源代码
@return [String] 包含需求树的错误消息,
which is much more detailed & customizable than the default message
@param [Hash] opts 创建消息的选项。 @option opts [String] :solver_name 求解器的用户可见名称 @option opts [String] :possibility_type 可能性的通用名称 @option opts [Proc] :reduce_trees 减少需求树列表的 Proc @option opts [Proc] :printable_requirement 一个美化打印需求的 Proc @option opts [Proc] :additional_message_for_conflict 一个附加的 Proc
messages for each conflict
@option opts [Proc] :version_for_spec 一个返回规范版本号的 Proc
possibility
# File rubygems/vendor/molinillo/lib/molinillo/errors.rb, line 97 def message_with_trees(opts = {}) solver_name = opts.delete(:solver_name) { self.class.name.split('::').first } possibility_type = opts.delete(:possibility_type) { 'possibility named' } reduce_trees = opts.delete(:reduce_trees) { proc { |trees| trees.uniq.sort_by(&:to_s) } } printable_requirement = opts.delete(:printable_requirement) { proc { |req| req.to_s } } additional_message_for_conflict = opts.delete(:additional_message_for_conflict) { proc {} } version_for_spec = opts.delete(:version_for_spec) { proc(&:to_s) } incompatible_version_message_for_conflict = opts.delete(:incompatible_version_message_for_conflict) do proc do |name, _conflict| %(#{solver_name} could not find compatible versions for #{possibility_type} "#{name}":) end end full_message_for_conflict = opts.delete(:full_message_for_conflict) do proc do |name, conflict| o = "\n".dup << incompatible_version_message_for_conflict.call(name, conflict) << "\n" if conflict.locked_requirement o << %( In snapshot (#{name_for_locking_dependency_source}):\n) o << %( #{printable_requirement.call(conflict.locked_requirement)}\n) o << %(\n) end o << %( In #{name_for_explicit_dependency_source}:\n) trees = reduce_trees.call(conflict.requirement_trees) o << trees.map do |tree| t = ''.dup depth = 2 tree.each do |req| t << ' ' * depth << printable_requirement.call(req) unless tree.last == req if spec = conflict.activated_by_name[name_for(req)] t << %( was resolved to #{version_for_spec.call(spec)}, which) end t << %( depends on) end t << %(\n) depth += 1 end t end.join("\n") additional_message_for_conflict.call(o, name, conflict) o end end conflicts.sort.reduce(''.dup) do |o, (name, conflict)| o << full_message_for_conflict.call(name, conflict) end.strip end