Class: RailsAiBridge::Introspectors::TimezoneIntrospector

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_ai_bridge/introspectors/timezone_introspector.rb

Overview

Extracts timezone configuration from the host Rails application.

Reads config.time_zone and compares it with Time.zone (which Rails sets at boot from config.time_zone) to emit structured facts. This applies to every Rails app regardless of stack, so it always runs as part of ConfigIntrospector; it is not a preset-gated section.

Examples:

Output shape (booted app, matching zone)

{ time_zone: "UTC", time_zone_confirmed: true }

Output shape (configured app, runtime zone unavailable)

{ time_zone: "UTC", time_zone_confirmed: false }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ TimezoneIntrospector

Returns a new instance of TimezoneIntrospector.

Parameters:

  • app (Rails::Application) —

    host Rails application



22
23
24
# File 'lib/rails_ai_bridge/introspectors/timezone_introspector.rb', line 22

def initialize(app)
  @app = app
end

Instance Attribute Details

#app ⇒ Rails::Application (readonly)

Returns host Rails application.

Returns:

  • (Rails::Application) —

    host Rails application



19
20
21
# File 'lib/rails_ai_bridge/introspectors/timezone_introspector.rb', line 19

def app
  @app
end

Instance Method Details

#call ⇒ Hash

Builds timezone facts. Time.zone is set by Rails at boot from config.time_zone. Confirmation compares IANA identifiers so Rails names and their IANA identifiers agree. An unavailable or different runtime zone leaves the configured value unconfirmed.

Returns:

  • (Hash) —

    timezone facts, or { error: message } on failure



32
33
34
35
36
37
38
39
40
41
# File 'lib/rails_ai_bridge/introspectors/timezone_introspector.rb', line 32

def call
  configured = app.config.time_zone.to_s
  runtime_identifier = Time.zone&.tzinfo&.identifier
  {
    time_zone: configured,
    time_zone_confirmed: (runtime_identifier && runtime_identifier == ActiveSupport::TimeZone[configured]&.tzinfo&.identifier) || false
  }
rescue StandardError => error
  { error: error.message }
end