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.



52
53
54
55
56
57
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 52

def initialize(app)
  @app = app

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

Instance Method Details

#ignore(path = nil, &block) ⇒ void

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



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 62

def ignore(path=nil, &block)
  if path.is_a? Regexp
    @ignored_callbacks << Proc.new {|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.new {|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.new {|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:

Returns:

  • (Boolean)


84
85
86
87
# File 'lib/middleman-core/sitemap/extensions/ignores.rb', line 84

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