Class: Bundler::Overrule::Rule
- Inherits:
-
Object
- Object
- Bundler::Overrule::Rule
- 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).
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#applies_to?(dependency_name) ⇒ Boolean
Does this rule apply to the given dependency name?.
-
#comparable_requirement ⇒ Object
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. - #hash ⇒ Object
-
#initialize(name, reason: nil) ⇒ Rule
constructor
A new instance of Rule.
- #to_s ⇒ Object
-
#type ⇒ Object
:force or :ban — subclasses define it.
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/bundler/overrule/rule.rb', line 13 def name @name end |
#reason ⇒ Object (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?
27 28 29 |
# File 'lib/bundler/overrule/rule.rb', line 27 def applies_to?(dependency_name) name == dependency_name end |
#comparable_requirement ⇒ Object
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 |
#hash ⇒ Object
37 38 39 |
# File 'lib/bundler/overrule/rule.rb', line 37 def hash [self.class, name, comparable_requirement].hash end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/bundler/overrule/rule.rb', line 47 def to_s raise NotImplementedError end |
#type ⇒ Object
:force or :ban — subclasses define it.
22 23 24 |
# File 'lib/bundler/overrule/rule.rb', line 22 def type raise NotImplementedError end |