Class: CukeLinter::FeatureWithTooManyDifferentTagsLinter

Inherits:
Linter
  • Object
show all
Defined in:
lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb

Overview

A linter that detects features that contain too many different tags

Instance Method Summary collapse

Methods inherited from Linter

#initialize, #lint, #name

Constructor Details

This class inherits a constructor from CukeLinter::Linter

Instance Method Details

#configure(options) ⇒ Object

Changes the linting settings on the linter using the provided configuration



8
9
10
# File 'lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb', line 8

def configure(options)
  @tag_threshold = options['TagCountThreshold']
end

#messageObject

The message used to describe the problem that has been found



33
34
35
# File 'lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb', line 33

def message
  "Feature contains too many different tags. #{@linted_tag_count} tags found (max #{@linted_tag_threshold})."
end

#rule(model) ⇒ Object

The rule used to determine if a model has a problem



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cuke_linter/linters/feature_with_too_many_different_tags_linter.rb', line 13

def rule(model)
  return false unless model.is_a?(CukeModeler::Feature)

  tags = model.tags

  model.each_descendant do |descendant_model|
    if descendant_model.respond_to?(:tags)
      tags.concat(descendant_model.tags)
    end
  end

  tags = tags.collect(&:name).uniq

  @linted_tag_threshold = @tag_threshold || 10
  @linted_tag_count     = tags.count

  @linted_tag_count > @linted_tag_threshold
end