Class: Yardstick::Rule Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/yardstick/rule.rb

Overview

This class is abstract.

Base class of every rule

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, config = RuleConfig.new) ⇒ Yardstick::Rule

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes a rule

Parameters:


68
69
70
71
# File 'lib/yardstick/rule.rb', line 68

def initialize(document, config = RuleConfig.new)
  @document = document
  @config   = config
end

Class Attribute Details

.descriptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Description of the rule

This is shown when a rule is invalid

Returns:

  • (String)

20
21
22
# File 'lib/yardstick/rule.rb', line 20

def description
  @description
end

Instance Attribute Details

#documentDocument (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return document that current rule is using

Returns:


57
58
59
# File 'lib/yardstick/rule.rb', line 57

def document
  @document
end

Class Method Details

.coerce(document, config) ⇒ Yardstick::Rule

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Makes a new instance of rule using given config

Parameters:

Returns:


48
49
50
# File 'lib/yardstick/rule.rb', line 48

def self.coerce(document, config)
  new(document, config.for_rule(self))
end

Instance Method Details

#enabled?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if rule is enabled in current context

Returns:

  • (Boolean)

    true if enabled


81
82
83
# File 'lib/yardstick/rule.rb', line 81

def enabled?
  @config.enabled_for_path?(@document.path)
end

#validatable?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Checks if the rule is validatable for given document

Returns:

  • (Boolean)

90
91
92
# File 'lib/yardstick/rule.rb', line 90

def validatable?
  true
end