Class: RoutesApiSpecGenerator::ControllerInspector
- Inherits:
-
Object
- Object
- RoutesApiSpecGenerator::ControllerInspector
- Defined in:
- lib/routes_api_spec_generator/controller_inspector.rb
Constant Summary collapse
- SERVICE_PATTERNS =
{ /metrics_payload\(::Insights::(\w+)\)/ => :insights, /::Channels::ResultsAggregatorService/ => :aggregator, /::Channels::StatsFinder/ => :stats_finder }.freeze
Instance Method Summary collapse
-
#initialize(rails_root:) ⇒ ControllerInspector
constructor
A new instance of ControllerInspector.
- #inspect(controller_path, action) ⇒ Object
Constructor Details
#initialize(rails_root:) ⇒ ControllerInspector
Returns a new instance of ControllerInspector.
13 14 15 |
# File 'lib/routes_api_spec_generator/controller_inspector.rb', line 13 def initialize(rails_root:) @rails_root = Pathname.new(rails_root) end |
Instance Method Details
#inspect(controller_path, action) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/routes_api_spec_generator/controller_inspector.rb', line 17 def inspect(controller_path, action) file = controller_file(controller_path) return {} unless file && File.exist?(file) source = File.read(file) hints = { permitted_params: extract_permit(source), skip_timezone: source.include?('skip_before_action :validate_timezone'), service_class: extract_service_for_action(source, action), service_pattern: nil } hints[:service_pattern] = infer_service_pattern(hints[:service_class], source) hints[:template] = infer_template(controller_path, action, hints, source) hints[:tenant_header] = controller_path.include?('insights') ? 'X-Tenant-ID' : 'Tenant-ID' hints[:channel] = infer_channel(action) hints end |