Class: MarkdownLint::Rule
- Inherits:
-
Object
- Object
- MarkdownLint::Rule
- Defined in:
- lib/mdl/ruleset.rb
Overview
defines a single rule
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #aliases(*aliases) ⇒ Object
- #check(&block) ⇒ Object
- #docs(url = nil, &block) ⇒ Object
- #docs_url ⇒ Object
-
#initialize(id, description, fallback_docs: nil, &block) ⇒ Rule
constructor
A new instance of Rule.
- #params(params = nil) ⇒ Object
- #tags(*tags) ⇒ Object
Constructor Details
#initialize(id, description, fallback_docs: nil, &block) ⇒ Rule
Returns a new instance of Rule.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mdl/ruleset.rb', line 6 def initialize(id, description, fallback_docs: nil, &block) @id = id @description = description @generate_docs = fallback_docs @docs_overridden = false @aliases = [] @tags = [] @params = {} instance_eval(&block) end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
4 5 6 |
# File 'lib/mdl/ruleset.rb', line 4 def description @description end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/mdl/ruleset.rb', line 4 def id @id end |
Instance Method Details
#aliases(*aliases) ⇒ Object
27 28 29 30 |
# File 'lib/mdl/ruleset.rb', line 27 def aliases(*aliases) @aliases.concat(aliases) @aliases end |
#check(&block) ⇒ Object
17 18 19 20 |
# File 'lib/mdl/ruleset.rb', line 17 def check(&block) @check = block unless block.nil? @check end |
#docs(url = nil, &block) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mdl/ruleset.rb', line 37 def docs(url = nil, &block) if block_given? != url.nil? raise ArgumentError, 'Give either a URL or a block, not both' end raise 'A docs url is already set within this rule' if @docs_overridden @generate_docs = block_given? ? block : lambda { |_, _| url } @docs_overridden = true end |
#docs_url ⇒ Object
48 49 50 |
# File 'lib/mdl/ruleset.rb', line 48 def docs_url @generate_docs&.call(id, description) end |
#params(params = nil) ⇒ Object
32 33 34 35 |
# File 'lib/mdl/ruleset.rb', line 32 def params(params = nil) @params.update(params) unless params.nil? @params end |
#tags(*tags) ⇒ Object
22 23 24 25 |
# File 'lib/mdl/ruleset.rb', line 22 def (*) @tags = .flatten.map(&:to_sym) unless .empty? @tags end |