Sha256: e09f9a1293a762e44f5a10ff2c6a6a5b706b52a2c7bda5d00ca11118ef43787e

Contents?: true

Size: 1.26 KB

Versions: 187

Compression:

Stored size: 1.26 KB

Contents

require 'mspec/runner/actions/filter'
require 'mspec/runner/actions/taglist'

# TagPurgeAction - removes all tags not matching any spec
# descriptions.
class TagPurgeAction < TagListAction
  attr_reader :matching

  def initialize
    @matching = []
    @filter   = nil
    @tags     = nil
  end

  # Prints a banner about purging tags.
  def start
    print "\nRemoving tags not matching any specs\n\n"
  end

  # Creates a MatchFilter for all tags.
  def load
    @filter = nil
    @tags = MSpec.read_tags self
    desc = @tags.map { |t| t.description }
    @filter = MatchFilter.new(nil, *desc) unless desc.empty?
  end

  # Saves any matching tags
  def after(state)
    @matching << state.description if self === state.description
  end

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

  def register
    super
    MSpec.register :unload, self
  end

  def unregister
    super
    MSpec.unregister :unload, self
  end
end

Version data entries

187 entries across 163 versions & 4 rubygems

Version Path
rhodes-3.3.2.beta.3 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.3.2.beta.2 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.3.2.beta.1 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.3.1 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.3.0 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.3.0.beta.3 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.3.0.beta.2 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.3.0.beta.1 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.3 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.2 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.2.beta lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.1 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.0 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.0.beta.9 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.0.beta.8 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.0.beta.7 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.0.beta.6 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.0.beta.5 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.0.beta.4 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb
rhodes-3.2.0.beta.2 lib/extensions/mspec/mspec/runner/actions/tagpurge.rb