Class: Bundler::Overrule::Rule

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

Overview

A single override declared in the Gemfile.

Rules are immutable value objects. Equality is by content, which is what lets us tell a harmless Gemfile re-evaluation (Bundler evaluates the Gemfile more than once per run) apart from a genuine duplicate rule (B4).

Direct Known Subclasses

Ban, Force, Swap

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, reason: nil) ⇒ Rule

Returns a new instance of Rule.



15
16
17
18
19
# File 'lib/bundler/overrule/rule.rb', line 15

def initialize(name, reason: nil)
  @name = normalize_name(name)
  @reason = normalize_reason(reason)
  freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/bundler/overrule/rule.rb', line 13

def name
  @name
end

#reasonObject (readonly)

Returns the value of attribute reason.



13
14
15
# File 'lib/bundler/overrule/rule.rb', line 13

def reason
  @reason
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



31
32
33
34
# File 'lib/bundler/overrule/rule.rb', line 31

def ==(other)
  other.is_a?(Rule) && other.type == type && other.name == name &&
    other.comparable_requirement == comparable_requirement
end

#applies_to?(dependency_name) ⇒ Boolean

Does this rule apply to the given dependency name?

Returns:

  • (Boolean)


27
28
29
# File 'lib/bundler/overrule/rule.rb', line 27

def applies_to?(dependency_name)
  name == dependency_name
end

#comparable_requirementObject

Rules that differ only by reason: are still the same rule; we do not want to error on a re-run just because someone reworded a comment.



43
44
45
# File 'lib/bundler/overrule/rule.rb', line 43

def comparable_requirement
  nil
end

#hashObject



37
38
39
# File 'lib/bundler/overrule/rule.rb', line 37

def hash
  [self.class, name, comparable_requirement].hash
end

#to_sObject

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/bundler/overrule/rule.rb', line 47

def to_s
  raise NotImplementedError
end

#typeObject

:force or :ban — subclasses define it.

Raises:

  • (NotImplementedError)


22
23
24
# File 'lib/bundler/overrule/rule.rb', line 22

def type
  raise NotImplementedError
end