Module: Bundler::Overrule
- Defined in:
- lib/bundler/overrule.rb,
lib/bundler/overrule/dsl.rb,
lib/bundler/overrule/rule.rb,
lib/bundler/overrule/errors.rb,
lib/bundler/overrule/command.rb,
lib/bundler/overrule/patcher.rb,
lib/bundler/overrule/version.rb,
lib/bundler/overrule/registry.rb,
lib/bundler/overrule/reporter.rb,
lib/bundler/overrule/dependency_rewriter.rb
Overview
Force, ban, and swap gem versions from your Gemfile.
Nothing here patches Bundler until the first rule is declared: with no rules, resolution is byte-identical to vanilla Bundler (G4).
Defined Under Namespace
Modules: DependencyRewriter, Dsl, Patcher Classes: Ban, BannedDirectDependencyError, Command, DuplicateRuleError, Edge, Error, Force, InvalidRuleError, Registry, Reporter, Rule, UnsupportedBundlerError
Constant Summary collapse
- SUPPORTED_BUNDLER =
Verified against 2.6.x, 2.7.x and 4.0.x. The upper bound is deliberately loose — Patcher also structurally verifies every patch target, which is a better guard than a version number, and refuses to run if one is missing.
An Array, not a comma-joined String: Gem::Requirement.create(">= 2.6, < 5") raises BadRequirementError.
[">= 2.6", "< 5"].freeze
- SUPPORTED_BUNDLER_DESCRIPTION =
SUPPORTED_BUNDLER.join(", ").freeze
- VERSION =
"0.2.0"
Class Method Summary collapse
- .active? ⇒ Boolean
- .ban(name, reason: nil) ⇒ Object
- .definition_built? ⇒ Boolean
-
.finalize! ⇒ Object
Print the summary and persist the state file.
- .force(name, requirement, reason: nil) ⇒ Object
- .note_definition_built! ⇒ Object
-
.plugin_prepass?(dsl) ⇒ Boolean
True while Bundler is doing its pre-pass over the Gemfile looking for
pluginlines (Bundler::Plugin.gemfile_install). - .register(rule) ⇒ Object
- .registry ⇒ Object
- .reporter ⇒ Object
-
.reset! ⇒ Object
Test hook.
-
.rewrite_gemfile_dependencies!(dependencies) ⇒ Object
Called from the Dsl#to_definition seam with the Gemfile's own dependency array, which we mutate in place.
-
.rules_changed? ⇒ Boolean
Has the rule set changed since the lockfile was last written? Used to defeat Bundler's "lockfile looks current, skip resolution" fast path.
-
.suppress_summary! ⇒ Object
bundle overrule listprints its own report; the install-time "YOU own the consequences" banner on top of it would just be noise. - .suppress_summary? ⇒ Boolean
Class Method Details
.active? ⇒ Boolean
125 126 127 |
# File 'lib/bundler/overrule.rb', line 125 def active? registry.any? end |
.ban(name, reason: nil) ⇒ Object
54 55 56 |
# File 'lib/bundler/overrule.rb', line 54 def ban(name, reason: nil) register(Ban.new(name, reason: reason)) end |
.definition_built? ⇒ Boolean
108 109 110 |
# File 'lib/bundler/overrule.rb', line 108 def definition_built? @definition_built ||= false end |
.finalize! ⇒ Object
Print the summary and persist the state file. Idempotent — it is reachable from both the plugin hook and the at_exit fallback.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/bundler/overrule.rb', line 114 def finalize! return if @finalized || registry.empty? || !definition_built? @finalized = true reporter.print_summary unless suppress_summary? reporter.write_state! rescue StandardError => e # Reporting must never be the thing that breaks an install. ::Bundler.ui.warn("[bundler-overrule] could not write report: #{e.}") end |
.force(name, requirement, reason: nil) ⇒ Object
50 51 52 |
# File 'lib/bundler/overrule.rb', line 50 def force(name, requirement, reason: nil) register(Force.new(name, requirement, reason: reason)) end |
.note_definition_built! ⇒ Object
94 95 96 |
# File 'lib/bundler/overrule.rb', line 94 def note_definition_built! @definition_built = true end |
.plugin_prepass?(dsl) ⇒ Boolean
True while Bundler is doing its pre-pass over the Gemfile looking for
plugin lines (Bundler::Plugin.gemfile_install). Nothing is resolved
in that pass.
90 91 92 |
# File 'lib/bundler/overrule.rb', line 90 def plugin_prepass?(dsl) defined?(::Bundler::Plugin::DSL) && dsl.is_a?(::Bundler::Plugin::DSL) end |
.register(rule) ⇒ Object
58 59 60 61 62 |
# File 'lib/bundler/overrule.rb', line 58 def register(rule) rule = registry.add(rule) Patcher.apply! rule end |
.registry ⇒ Object
30 31 32 |
# File 'lib/bundler/overrule.rb', line 30 def registry @registry ||= Registry.new end |
.reporter ⇒ Object
34 35 36 |
# File 'lib/bundler/overrule.rb', line 34 def reporter @reporter ||= Reporter.new(registry) end |
.reset! ⇒ Object
Test hook.
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bundler/overrule.rb', line 39 def reset! @registry = nil @reporter = nil @rules_changed = nil @finalized = false @definition_built = false @suppress_summary = false Patcher.reset! self end |
.rewrite_gemfile_dependencies!(dependencies) ⇒ Object
Called from the Dsl#to_definition seam with the Gemfile's own dependency array, which we mutate in place.
force has to beat a Gemfile pin (B2), and ban of a directly
required gem is a user error, not something to silently honour (B6).
69 70 71 72 73 74 75 |
# File 'lib/bundler/overrule.rb', line 69 def rewrite_gemfile_dependencies!(dependencies) return dependencies if registry.empty? || dependencies.nil? reject_banned_direct_dependencies!(dependencies) apply_forces_to_gemfile!(dependencies) dependencies end |
.rules_changed? ⇒ Boolean
Has the rule set changed since the lockfile was last written? Used to defeat Bundler's "lockfile looks current, skip resolution" fast path.
79 80 81 82 83 84 85 |
# File 'lib/bundler/overrule.rb', line 79 def rules_changed? return false if registry.empty? return @rules_changed unless @rules_changed.nil? state = reporter.read_state @rules_changed = state.nil? || state["fingerprint"] != registry.fingerprint end |
.suppress_summary! ⇒ Object
bundle overrule list prints its own report; the install-time "YOU own
the consequences" banner on top of it would just be noise.
100 101 102 |
# File 'lib/bundler/overrule.rb', line 100 def suppress_summary! @suppress_summary = true end |
.suppress_summary? ⇒ Boolean
104 105 106 |
# File 'lib/bundler/overrule.rb', line 104 def suppress_summary? @suppress_summary ||= false end |