diff --git a/lib/regexp-examples/constants.rb b/lib/regexp-examples/constants.rb index 666cd20..d43224c 100644 --- a/lib/regexp-examples/constants.rb +++ b/lib/regexp-examples/constants.rb @@ -33,7 +33,11 @@ def config=(**args) end def config - Thread.current[:regexp_examples_config] ||= {} + Thread.current[:regexp_examples_config] ||= { + max_repeater_variance: MAX_REPEATER_VARIANCE_DEFAULT, + max_group_results: MAX_GROUP_RESULTS_DEFAULT, + max_results_limit: MAX_RESULTS_LIMIT_DEFAULT + } end end # The maximum variance for any given repeater, to prevent a huge/infinite number of @@ -44,21 +48,18 @@ def config # .{,3} is equivalent to .{0,2} # .{3,8} is equivalent to .{3,5} MAX_REPEATER_VARIANCE_DEFAULT = 2 - self.max_repeater_variance = MAX_REPEATER_VARIANCE_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] MAX_GROUP_RESULTS_DEFAULT = 5 - self.max_group_results = MAX_GROUP_RESULTS_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!!!) MAX_RESULTS_LIMIT_DEFAULT = 10_000 - self.max_results_limit = MAX_RESULTS_LIMIT_DEFAULT end # Definitions of various special characters, used in regular expressions.