Class: Middleman::Sitemap::Extensions::Ignores::IgnoreManager

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-core/sitemap/extensions/ignores.rb

Overview

Class to handle managing ignores

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ IgnoreManager

Returns a new instance of IgnoreManager.



46
47
48
49
50
51
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 46

def initialize(app)
  @app = app

  # Array of callbacks which can ass ignored
  @ignored_callbacks = []
end

Instance Method Details

#ignore(path = nil, &block)

This method returns an undefined value.

Ignore a path or add an ignore callback

Parameters:

  • path (String, Regexp) (defaults to: nil)

    Path glob expression, or path regex



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 56

def ignore(path=nil, &block)
  if path.is_a? Regexp
    @ignored_callbacks << proc { |p| p =~ path }
  elsif path.is_a? String
    path_clean = ::Middleman::Util.normalize_path(path)
    if path_clean.include?('*') # It's a glob
      @ignored_callbacks << proc { |p| File.fnmatch(path_clean, p) }
    else
      # Add a specific-path ignore unless that path is already covered
      return if ignored?(path_clean)
      @ignored_callbacks << proc { |p| p == path_clean }
    end
  elsif block_given?
    @ignored_callbacks << block
  end

  @app.sitemap.invalidate_resources_not_ignored_cache!
end

#ignored?(path) ⇒ Boolean

Whether a path is ignored

Parameters:

  • path (String)

Returns:

  • (Boolean)


78
79
80
81
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 78

def ignored?(path)
  path_clean = ::Middleman::Util.normalize_path(path)
  @ignored_callbacks.any? { |b| b.call(path_clean) }
end