Class: RegexpExamples::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/regexp-examples/config.rb

Overview

Configuration settings to limit the number/length of Regexp examples generated

Constant Summary collapse

MAX_REPEATER_VARIANCE_DEFAULT =

The maximum variance for any given repeater, to prevent a huge/infinite number of examples from being listed. For example, if self.max_repeater_variance = 2 then: .* is equivalent to .0,2 .+ is equivalent to .1,3 .2, is equivalent to .2,4 .,3 is equivalent to .0,2 .3,8 is equivalent to .3,5

2
MAX_GROUP_RESULTS_DEFAULT =

Maximum number of characters returned from a char set, to reduce output spam For example, if self.max_group_results = 5 then: d is equivalent to [01234] w is equivalent to [abcde]

5
MAX_RESULTS_LIMIT_DEFAULT =

Maximum number of results to be generated, for Regexp#examples This is to prevent the system “freezing” when given instructions like: /[ab]30/.examples (Which would attempt to generate 2**30 == 1073741824 examples!!!)

10_000

Class Method Summary collapse

Class Method Details

.with_configuration(**new_config) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/regexp-examples/config.rb', line 26

def with_configuration(**new_config)
  original_config = config.dup

  begin
    update_config(**new_config)
    result = yield
  ensure
    update_config(**original_config)
  end

  result
end