@@ -148,15 +148,9 @@ When generating examples, the gem uses 3 configurable values to limit how many e
148148
149149` Rexexp#examples ` makes use of * all* these options; ` Rexexp#random_example ` only uses ` max_repeater_variance ` , since the other options are redundant.
150150
151- To use an alternative value, you can either define a different default value:
151+ ### Defining custom configuration values
152152
153- ``` ruby
154- RegexpExamples ::ResultCountLimiters .max_repeater_variance = 5
155- RegexpExamples ::ResultCountLimiters .max_group_results = 10
156- RegexpExamples ::ResultCountLimiters .max_results_limit = 20000
157- ```
158-
159- Or, simply pass the configuration option as a parameter:
153+ To use an alternative value, you can either pass the configuration option as a parameter:
160154
161155``` ruby
162156/a*/ .examples(max_repeater_variance: 5 )
@@ -169,19 +163,41 @@ Or, simply pass the configuration option as a parameter:
169163 # => "A very unlikely result!"
170164```
171165
166+ Or, set an alternative value * within a block* :
167+
168+ ``` ruby
169+ RegexpExamples ::Config .with_configuration(max_repeater_variance: 5 ) do
170+ # ...
171+ end
172+ ```
173+
174+ Or, globally set a different default value:
175+
176+ ``` ruby
177+ # e.g In a rails project, you may wish to place this in
178+ # config/initializers/regexp_examples.rb
179+ RegexpExamples ::Config .max_repeater_variance = 5
180+ RegexpExamples ::Config .max_group_results = 10
181+ RegexpExamples ::Config .max_results_limit = 20000
182+ ```
183+
172184A sensible use case might be, for example, to generate all 1-5 digit strings:
173185
174186``` ruby
175187/\d {1,5} / .examples(max_repeater_variance: 4 , max_group_results: 10 , max_results_limit: 100000 )
176188 # => ['0', '1', '2', ..., '99998', '99999']
177189```
178190
191+ ### Configuration Notes
192+
179193Due to code optimisation, ` Regexp#random_example ` runs pretty fast even on very complex patterns.
180194(I.e. It's typically a _ lot_ faster than using ` /pattern/.examples.sample(1) ` .)
181195For instance, the following takes no more than ~ 1 second on my machine:
182196
183197` /.*\w+\d{100}/.random_example(max_repeater_variance: 1000) `
184198
199+ All forms of configuration mentioned above ** are thread safe** .
200+
185201## Bugs and TODOs
186202
187203There are no known major bugs with this library. However, there are a few obscure issues that you * may* encounter:
0 commit comments