Class: Bundler::Overrule::Swap

Inherits:
Rule
  • Object
show all
Defined in:
lib/bundler/overrule/rule.rb

Overview

swap 'httpclient', with: 'byroot-httpclient' — point every edge at a different gem instead.

The substitute defaults to >= 0 rather than inheriting the original edge's requirement: a fork's version numbers are its own lineage, and carrying ~> 2.8 onto a fork that restarted at 1.0 would be unresolvable for reasons the user never wrote down. Pass version: to constrain it.

Constant Summary collapse

DEFAULT_REQUIREMENT =
">= 0"

Instance Attribute Summary collapse

Attributes inherited from Rule

#name, #reason

Instance Method Summary collapse

Methods inherited from Rule

#==, #applies_to?, #hash

Constructor Details

#initialize(name, replacement, version: nil, reason: nil) ⇒ Swap

Returns a new instance of Swap.



124
125
126
127
128
# File 'lib/bundler/overrule/rule.rb', line 124

def initialize(name, replacement, version: nil, reason: nil)
  @replacement = normalize_replacement(replacement, name)
  @requirement = build_requirement(version || DEFAULT_REQUIREMENT)
  super(name, reason: reason)
end

Instance Attribute Details

#replacementObject (readonly)

Returns the value of attribute replacement.



122
123
124
# File 'lib/bundler/overrule/rule.rb', line 122

def replacement
  @replacement
end

#requirementObject (readonly)

Returns the value of attribute requirement.



122
123
124
# File 'lib/bundler/overrule/rule.rb', line 122

def requirement
  @requirement
end

Instance Method Details

#comparable_requirementObject



134
135
136
# File 'lib/bundler/overrule/rule.rb', line 134

def comparable_requirement
  "#{replacement} #{requirement}"
end

#pinned?Boolean

True when the caller pinned the substitute, rather than taking >= 0.

Returns:

  • (Boolean)


139
140
141
# File 'lib/bundler/overrule/rule.rb', line 139

def pinned?
  requirement != ::Gem::Requirement.create(DEFAULT_REQUIREMENT)
end

#to_sObject



143
144
145
# File 'lib/bundler/overrule/rule.rb', line 143

def to_s
  pinned? ? "swap #{name} with #{replacement} #{requirement}" : "swap #{name} with #{replacement}"
end

#typeObject



130
131
132
# File 'lib/bundler/overrule/rule.rb', line 130

def type
  :swap
end