class TagPurgeAction

TagPurgeAction - removes all tags not matching any spec descriptions.

Attributes

matching[R]

Public Class Methods

new() click to toggle source
# File lib/mspec/runner/actions/tagpurge.rb, line 9
def initialize
  @matching = []
  @filter   = nil
  @tags     = nil
end

Public Instance Methods

after(state) click to toggle source

Saves any matching tags

# File lib/mspec/runner/actions/tagpurge.rb, line 29
def after(state)
  @matching << state.description if self === state.description
end
load() click to toggle source

Creates a MatchFilter for all tags.

# File lib/mspec/runner/actions/tagpurge.rb, line 21
def load
  @filter = nil
  @tags = MSpec.read_tags self
  desc = @tags.map { |t| t.description }
  @filter = MatchFilter.new(nil, *desc) unless desc.empty?
end
register() click to toggle source
Calls superclass method TagListAction#register
# File lib/mspec/runner/actions/tagpurge.rb, line 47
def register
  super
  MSpec.register :unload, self
end
start() click to toggle source

Prints a banner about purging tags.

# File lib/mspec/runner/actions/tagpurge.rb, line 16
def start
  print "\nRemoving tags not matching any specs\n\n"
end
unload() click to toggle source

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).

# File lib/mspec/runner/actions/tagpurge.rb, line 36
def unload
  if @filter
    matched = @tags.select { |t| @matching.any? { |s| s == t.description } }
    MSpec.write_tags matched

    (@tags - matched).each { |t| print t.description, "\n" }
  else
    MSpec.delete_tags
  end
end
unregister() click to toggle source
Calls superclass method TagListAction#unregister
# File lib/mspec/runner/actions/tagpurge.rb, line 52
def unregister
  super
  MSpec.unregister :unload, self
end