Class: YARD::Bird::Rules
- Inherits:
-
Object
- Object
- YARD::Bird::Rules
- Defined in:
- lib/yard-bird/rules.rb
Class Method Summary collapse
-
.load ⇒ Object
Returns [Rules].
Instance Method Summary collapse
-
#initialize ⇒ Rules
constructor
Create new Rules object.
-
#inject_rules ⇒ Object
Rules are applied as YARD processes comments.
-
#load_rules ⇒ Object
Dot-bird filesa are loaded from ‘.yard/` project directory and sorted alphabetically.
-
#patterns ⇒ Object
Patterns to apply.
-
#When(pattern, &block) ⇒ Proc
Define a new rule.
Constructor Details
#initialize ⇒ Rules
Create new Rules object.
14 15 16 17 18 |
# File 'lib/yard-bird/rules.rb', line 14 def initialize() @patterns = {} load_rules inject_rules end |
Class Method Details
.load ⇒ Object
Returns [Rules]
9 10 11 |
# File 'lib/yard-bird/rules.rb', line 9 def self.load new end |
Instance Method Details
#inject_rules ⇒ Object
Rules are applied as YARD processes comments. All rules are applied in order until all rules have been tried, or a triggered rule returns a ‘:break` symbol, which will short-circuit further rule application.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/yard-bird/rules.rb', line 59 def inject_rules pats = patterns ::YARD::Docstring.class_eval do define_method :parse_comments do |comments| comments = comments.join("\n") if Array === comments result = nil pats.each do |pattern, block| if md = pattern.match(comments) result = instance_exec(md, comments, &block) #block.call(md) break if result == :break comments = result if String === result end end comments.to_s #r.to_s end end end |
#load_rules ⇒ Object
Dot-bird filesa are loaded from ‘.yard/` project directory and sorted alphabetically. The sorting is useful for controlling application order when using multiple files –simply number the files, e.g.
.yard/01_special.bird
.yard/02_tomdoc.bird
In the example the special rules will have precedence over the tomdoc rules.
32 33 34 35 36 37 |
# File 'lib/yard-bird/rules.rb', line 32 def load_rules files = Dir[".yard/*.bird"].sort files.each do |file| instance_eval(File.read(file), file) end end |
#patterns ⇒ Object
Patterns to apply.
52 53 54 |
# File 'lib/yard-bird/rules.rb', line 52 def patterns @patterns end |
#When(pattern, &block) ⇒ Proc
Define a new rule.
pattern - Regexp to match against comment.
block - Proc for handling pattern match.
45 46 47 |
# File 'lib/yard-bird/rules.rb', line 45 def When(pattern, &block) patterns[pattern] = block end |