Class: TagPurgeAction
- Inherits:
-
TagListAction
- Object
- TagListAction
- TagPurgeAction
- Defined in:
- lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
Overview
TagPurgeAction - removes all tags not matching any spec descriptions.
Instance Attribute Summary collapse
-
#matching ⇒ Object
readonly
Returns the value of attribute matching.
Instance Method Summary collapse
-
#after(state) ⇒ Object
Saves any matching tags.
-
#initialize ⇒ TagPurgeAction
constructor
A new instance of TagPurgeAction.
-
#load ⇒ Object
Creates a MatchFilter for all tags.
- #register ⇒ Object
-
#start ⇒ Object
Prints a banner about purging tags.
-
#unload ⇒ Object
Rewrites any matching tags.
- #unregister ⇒ Object
Methods inherited from TagListAction
Constructor Details
#initialize ⇒ TagPurgeAction
Returns a new instance of TagPurgeAction.
9 10 11 12 13 |
# File 'lib/extensions/mspec/mspec/runner/actions/tagpurge.rb', line 9 def initialize @matching = [] @filter = nil @tags = nil end |
Instance Attribute Details
#matching ⇒ Object (readonly)
Returns the value of attribute matching.
7 8 9 |
# File 'lib/extensions/mspec/mspec/runner/actions/tagpurge.rb', line 7 def matching @matching end |
Instance Method Details
#after(state) ⇒ Object
Saves any matching tags
29 30 31 |
# File 'lib/extensions/mspec/mspec/runner/actions/tagpurge.rb', line 29 def after(state) @matching << state.description if self === state.description end |
#load ⇒ Object
Creates a MatchFilter for all tags.
21 22 23 24 25 26 |
# File 'lib/extensions/mspec/mspec/runner/actions/tagpurge.rb', line 21 def load @filter = nil @tags = MSpec. self desc = @tags.map { |t| t.description } @filter = MatchFilter.new(nil, *desc) unless desc.empty? end |
#register ⇒ Object
47 48 49 50 |
# File 'lib/extensions/mspec/mspec/runner/actions/tagpurge.rb', line 47 def register super MSpec.register :unload, self end |
#start ⇒ Object
Prints a banner about purging tags.
16 17 18 |
# File 'lib/extensions/mspec/mspec/runner/actions/tagpurge.rb', line 16 def start print "\nRemoving tags not matching any specs\n\n" end |
#unload ⇒ Object
Rewrites any matching tags. Prints non-matching tags. Deletes the tag file if there were no tags (this cleans up empty or malformed tag files).
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/extensions/mspec/mspec/runner/actions/tagpurge.rb', line 36 def unload if @filter matched = @tags.select { |t| @matching.any? { |s| s == t.description } } MSpec. matched (@tags - matched).each { |t| print t.description, "\n" } else MSpec. end end |
#unregister ⇒ Object
52 53 54 55 |
# File 'lib/extensions/mspec/mspec/runner/actions/tagpurge.rb', line 52 def unregister super MSpec.unregister :unload, self end |