|
15 | 15 | require 'rspec/openapi/extractors'
|
16 | 16 | require 'rspec/openapi/extractors/rack'
|
17 | 17 |
|
18 |
| -if ENV['OPENAPI'] |
19 |
| - DEBUG_ENABLED = ['', '1', 'true'].include?(ENV['DEBUG']&.downcase) |
20 |
| - |
21 |
| - begin |
22 |
| - require 'hanami' |
23 |
| - rescue LoadError |
24 |
| - warn 'Hanami not detected' if DEBUG_ENABLED |
25 |
| - else |
26 |
| - require 'rspec/openapi/extractors/hanami' |
27 |
| - end |
| 18 | +module RSpec::OpenAPI |
| 19 | + class Config |
| 20 | + class << self |
| 21 | + attr_accessor :debug_enabled |
28 | 22 |
|
29 |
| - begin |
30 |
| - require 'rails' |
31 |
| - rescue LoadError |
32 |
| - warn 'Rails not detected' if DEBUG_ENABLED |
33 |
| - else |
34 |
| - require 'rspec/openapi/extractors/rails' |
| 23 | + def load_environment_settings |
| 24 | + @debug_enabled = ['', '1', 'true'].include?(ENV['DEBUG']&.downcase) |
| 25 | + end |
| 26 | + end |
35 | 27 | end
|
36 |
| -end |
37 | 28 |
|
38 |
| -require 'rspec/openapi/minitest_hooks' if Object.const_defined?('Minitest') |
39 |
| -require 'rspec/openapi/rspec_hooks' if ENV['OPENAPI'] && Object.const_defined?('RSpec') |
40 |
| - |
41 |
| -module RSpec::OpenAPI |
42 | 29 | @path = 'doc/openapi.yaml'
|
43 | 30 | @title = File.basename(Dir.pwd)
|
44 | 31 | @comment = nil
|
@@ -84,3 +71,26 @@ class << self
|
84 | 71 | attr_reader :config_filename
|
85 | 72 | end
|
86 | 73 | end
|
| 74 | + |
| 75 | +if ENV['OPENAPI'] |
| 76 | + RSpec::OpenAPI::Config.load_environment_settings |
| 77 | + |
| 78 | + begin |
| 79 | + require 'hanami' |
| 80 | + rescue LoadError |
| 81 | + warn 'Hanami not detected' if RSpec::OpenAPI::Config.debug_enabled |
| 82 | + else |
| 83 | + require 'rspec/openapi/extractors/hanami' |
| 84 | + end |
| 85 | + |
| 86 | + begin |
| 87 | + require 'rails' |
| 88 | + rescue LoadError |
| 89 | + warn 'Rails not detected' if RSpec::OpenAPI::Config.debug_enabled |
| 90 | + else |
| 91 | + require 'rspec/openapi/extractors/rails' |
| 92 | + end |
| 93 | +end |
| 94 | + |
| 95 | +require 'rspec/openapi/minitest_hooks' if Object.const_defined?('Minitest') |
| 96 | +require 'rspec/openapi/rspec_hooks' if ENV['OPENAPI'] && Object.const_defined?('RSpec') |
0 commit comments