Class: RuboCop::Cop::RSpecParity::SufficientContexts::BranchTally
- Inherits:
-
Object
- Object
- RuboCop::Cop::RSpecParity::SufficientContexts::BranchTally
- Defined in:
- lib/rubocop/cop/rspec_parity/sufficient_contexts.rb
Overview
Collection of Branch descriptors. Exposes the guard/regular/total/+ interface the rest of the cop (and PrivateMethodCallGraph) relies on —a sequence of guard clauses (‘return/raise/next … if/unless`) shares a single “all guards pass” fall-through counted once per method (see #branches_from) rather than once per guard. `with_origin` tags inlined branches as the call graph descends into single-use helpers.
Instance Attribute Summary collapse
-
#branches ⇒ Object
readonly
Returns the value of attribute branches.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #guard ⇒ Object
-
#initialize(branches = []) ⇒ BranchTally
constructor
A new instance of BranchTally.
- #regular ⇒ Object
- #total ⇒ Object
- #with_origin(name) ⇒ Object
Constructor Details
#initialize(branches = []) ⇒ BranchTally
Returns a new instance of BranchTally.
235 236 237 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 235 def initialize(branches = []) @branches = branches end |
Instance Attribute Details
#branches ⇒ Object (readonly)
Returns the value of attribute branches.
233 234 235 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 233 def branches @branches end |
Instance Method Details
#+(other) ⇒ Object
239 240 241 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 239 def +(other) BranchTally.new(branches + other.branches) end |
#guard ⇒ Object
243 244 245 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 243 def guard branches.count { |branch| branch.kind == :guard } end |
#regular ⇒ Object
247 248 249 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 247 def regular branches.count { |branch| branch.kind == :regular } end |
#total ⇒ Object
251 252 253 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 251 def total branches.size end |
#with_origin(name) ⇒ Object
255 256 257 258 259 |
# File 'lib/rubocop/cop/rspec_parity/sufficient_contexts.rb', line 255 def with_origin(name) BranchTally.new(branches.map do |branch| branch.origin ? branch : Branch.new(branch.kind, branch.label, branch.line, name, branch.detail) end) end |