Class: RailsAiBridge::Services::AppIntrospectionService
- Inherits:
-
RailsAiBridge::Service
- Object
- RailsAiBridge::Service
- RailsAiBridge::Services::AppIntrospectionService
- Defined in:
- lib/rails_ai_bridge/services/app_introspection_service.rb
Overview
Application service for running the app Introspector behind RailsAiBridge::Service.
Treats a top-level :error key or any nested value that is a Hash containing :error as failure
(per-introspector errors). Otherwise returns success with the introspection Hash as data.
Class Method Summary collapse
-
.call(app, only: nil, introspector_class: Introspector) ⇒ RailsAiBridge::Service::Result
Success with introspection data or failure with errors.
Instance Method Summary collapse
-
#call(only: nil) ⇒ RailsAiBridge::Service::Result
Performs introspection and wraps the outcome in a RailsAiBridge::Service::Result.
-
#initialize(app, introspector_class: Introspector) ⇒ AppIntrospectionService
constructor
A new instance of AppIntrospectionService.
Constructor Details
#initialize(app, introspector_class: Introspector) ⇒ AppIntrospectionService
Returns a new instance of AppIntrospectionService.
31 32 33 34 35 |
# File 'lib/rails_ai_bridge/services/app_introspection_service.rb', line 31 def initialize(app, introspector_class: Introspector) super() @app = app @introspector_class = introspector_class end |
Class Method Details
.call(app, only: nil, introspector_class: Introspector) ⇒ RailsAiBridge::Service::Result
Returns success with introspection data or failure with errors.
25 26 27 |
# File 'lib/rails_ai_bridge/services/app_introspection_service.rb', line 25 def self.call(app, only: nil, introspector_class: Introspector) new(app, introspector_class: introspector_class).call(only: only) end |
Instance Method Details
#call(only: nil) ⇒ RailsAiBridge::Service::Result
Performs introspection and wraps the outcome in a RailsAiBridge::Service::Result.
Fails when the introspector returns a non-Hash, a top-level :error entry, or when any entry's
value is a Hash with an :error key (nested per-introspector failure). In the nested case,
errors contains strings "<key>: <message>" for each failing entry.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rails_ai_bridge/services/app_introspection_service.rb', line 46 def call(only: nil) introspector = @introspector_class.new(@app) introspection_result = introspector.call(only: only) unless introspection_result.is_a?(Hash) return Service::Result.new(false, errors: ['Introspector must return a Hash']) end if introspection_result.key?(:error) return Service::Result.new(false, errors: ["Introspector returned error: #{introspection_result[:error]}"]) end nested_errors = introspection_result.filter_map do |name, payload| next unless payload.is_a?(Hash) && payload.key?(:error) "#{name}: #{payload[:error]}" end return Service::Result.new(false, errors: nested_errors) if nested_errors.any? Service::Result.new(true, data: introspection_result) rescue StandardError => error Service::Result.new(false, errors: [error.]) end |