Class: Mustermann::PatternCache Private

Inherits:
Object
  • Object
show all
Defined in:
lib/mustermann/pattern_cache.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

Mustermann::Pattern.new (which is used by new) will reuse instances that have not yet been garbage collected. You only need an extra cache if you do not keep a reference to the patterns around.

A simple, persistent cache for creating repositories.

Examples:

require 'mustermann/pattern_cache'
cache = Mustermann::PatternCache.new

# use this instead of Mustermann.new
pattern = cache.create_pattern("/:name", type: :rails)

API:

  • private

Instance Method Summary collapse

Constructor Details

#initialize(**pattern_options) ⇒ PatternCache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of PatternCache.

Parameters:

API:

  • private



23
24
25
26
27
# File 'lib/mustermann/pattern_cache.rb', line 23

def initialize(**pattern_options)
  @cached          = Set.new
  @mutex           = Mutex.new
  @pattern_options = pattern_options
end

Instance Method Details

#clearObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Removes all pattern instances from the cache.

API:

  • private



40
41
42
# File 'lib/mustermann/pattern_cache.rb', line 40

def clear
  @mutex.synchronize { @cached.clear }
end

#create_pattern(string, **pattern_options) ⇒ Mustermann::Pattern

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns pattern corresponding to string.

Parameters:

  • The representation of the pattern

  • The options hash

Returns:

  • pattern corresponding to string.

Raises:

  • if the passed object cannot be converted to a pattern

  • if the type is not supported

  • if some option is not supported

  • if the pattern can’t be generated from the string

See Also:

API:

  • private



33
34
35
36
37
# File 'lib/mustermann/pattern_cache.rb', line 33

def create_pattern(string, **pattern_options)
  pattern = Mustermann.new(string, **pattern_options, **@pattern_options)
  @mutex.synchronize { @cached.add(pattern) } unless @cached.include? pattern
  pattern
end

#sizeInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns number of currently cached patterns.

Returns:

  • number of currently cached patterns

API:

  • private



45
46
47
# File 'lib/mustermann/pattern_cache.rb', line 45

def size
  @mutex.synchronize { @cached.size }
end