Open-Source Wikis

/

Ruby on Rails

/

Packages

/

Active Support

rails/rails

Active Support

Active contributors: rafaelfranca, jeremy, jonhefner

Purpose

Active Support is the bottom of the Rails stack. It provides Ruby standard library extensions, shared infrastructure (caching, instrumentation, logging, error reporting), and utilities used by every other component. It can also be used standalone in non-Rails Ruby applications.

Source: activesupport/lib/active_support/. This is one of the largest components by line count (~32K lines in lib/) but it is conceptually a grab bag rather than a single subsystem.

Directory layout

activesupport/
├── lib/
│   └── active_support/
│       ├── core_ext/             # Patches to stdlib classes (String, Hash, Array, ...)
│       ├── cache/                # Cache stores: memory, file, mem_cache, redis, null
│       ├── notifications/        # Pub/sub bus
│       ├── concurrency/          # Thread primitives
│       ├── current_attributes/   # Per-request global state
│       ├── dependencies/         # Autoload + Zeitwerk integration
│       ├── deprecation/          # Deprecation warnings infrastructure
│       ├── duration/             # 1.day, 3.weeks etc.
│       ├── error_reporter/       # Captured exception reporting
│       ├── event_reporter/       # Structured event emission
│       ├── execution_context/    # Per-job/request context
│       ├── inflector/            # pluralize / singularize / etc.
│       ├── messages/             # Signed and encrypted message verifiers
│       ├── notifications/        # ActiveSupport::Notifications
│       ├── number_helper/        # Formatting numbers, currency, file sizes
│       ├── testing/              # TestCase, parallelization, time helpers
│       ├── values/               # Time zone definitions
│       ├── xml_mini/             # XML parsers
│       └── …                     # ~80 top-level files for the rest
├── test/
└── activesupport.gemspec

Key abstractions

Constant File Purpose
ActiveSupport::Concern activesupport/lib/active_support/concern.rb Mixin pattern with class methods and dependency resolution
ActiveSupport::Notifications activesupport/lib/active_support/notifications.rb Pub/sub event bus used everywhere in Rails
ActiveSupport::Cache::Store activesupport/lib/active_support/cache.rb Base class for cache stores (memory, redis, mem_cache, file)
ActiveSupport::Inflector activesupport/lib/active_support/inflector.rb Pluralization, classification, humanization
ActiveSupport::Deprecation activesupport/lib/active_support/deprecation.rb Per-component deprecation warnings
ActiveSupport::CurrentAttributes activesupport/lib/active_support/current_attributes.rb Thread-local "request-scoped globals"
ActiveSupport::ErrorReporter activesupport/lib/active_support/error_reporter.rb Captured-exception reporting (Rails.error.report)
ActiveSupport::EventReporter activesupport/lib/active_support/event_reporter/ Structured event emission
ActiveSupport::Executor / Reloader activesupport/lib/active_support/execution_wrapper.rb, reloader.rb Wrap units of work for code reloading
ActiveSupport::TestCase activesupport/lib/active_support/test_case.rb Base class for every test in Rails
ActiveSupport::TimeZone / Duration activesupport/lib/active_support/time_zone.rb, duration.rb Time-zone-aware time arithmetic

Core extensions (core_ext/)

active_support/core_ext/ is the most touched directory in the framework. Each file extends one stdlib class and can be required in isolation:

require "active_support/core_ext/string/inflections"
"post".pluralize  # => "posts"

Top-level groupings:

  • array/in_groups, to_sentence, extract_options!, wrap, etc.
  • hash/deep_merge, with_indifferent_access, slice/except extensions, to_query.
  • string/pluralize, singularize, camelize, parameterize, truncate, mb_chars.
  • numeric/1.day.ago, 1.megabyte, 42.percent.
  • date/, date_time/, time/at_beginning_of_day, since, ago, in_time_zone.
  • module/delegate, concerning, attr_internal, redefine_method.
  • object/try, presence, with, tap, then, to_query.
  • kernel/silence_warnings, suppress.

activesupport/lib/active_support/all.rb requires every core extension at once; in practice individual components require only what they use.

Notifications

ActiveSupport::Notifications is the publish/subscribe bus that powers logging, instrumentation, and observability in Rails. Every framework publishes events under a <verb>.<component> namespace (sql.active_record, process_action.action_controller, enqueue.active_job, etc.).

Implementation:

  • notifications.rb — public API (subscribe, instrument, publish).
  • notifications/fanout.rb — broadcasts events to subscribers.
  • notifications/instrumenter.rb — measures elapsed time and assembles payloads.

Each component uses Notifications via a LogSubscriber and a StructuredEventSubscriber, both rooted in Active Support:

  • active_support/log_subscriber.rb
  • active_support/structured_event_subscriber.rb

Cache stores

ActiveSupport::Cache::Store is the base for every cache backend. Built-in stores live in activesupport/lib/active_support/cache/:

  • memory_store.rb — process-local, default in development.
  • file_store.rb — disk-backed cache.
  • null_store.rb — no-op (for tests).
  • mem_cache_store.rb — Memcached.
  • redis_cache_store.rb — Redis.

Strategies for compression, serialization (Marshal, JSON, MessagePack), and coder fallbacks live in cache/strategy/ and cache/serializer_with_fallback.rb. The Solid Cache gem (solid_cache, separate repo) provides a database-backed adapter for Rails 8.

Concerns

ActiveSupport::Concern (activesupport/lib/active_support/concern.rb) is the standard way to package a Ruby module that needs:

  • Class methods (via class_methods do ... end).
  • Inclusion-time hooks (via included do ... end).
  • Dependency on other concerns.

It resolves include order so module A include B Just Works without writing included(base) boilerplate.

Current attributes

ActiveSupport::CurrentAttributes is per-request thread-local state. The canonical use is Current.user, set from a controller before_action. Implementation in activesupport/lib/active_support/current_attributes.rb. The state is reset before each request via the executor.

Error and event reporting

  • ActiveSupport::ErrorReporter — fan out captured exceptions to subscribers (Sentry, Honeybadger, etc.). Access as Rails.error.
  • ActiveSupport::EventReporter (newer, activesupport/lib/active_support/event_reporter/) — emit structured events for log aggregators.

Both are designed to be subscribed to from application initializers; framework code calls them directly when handling background errors.

Testing infrastructure

activesupport/lib/active_support/testing/:

  • assertions.rbassert_difference, assert_changes, assert_no_changes.
  • time_helpers.rbfreeze_time, travel_to, travel_back.
  • parallelization.rb — fork-based test parallelization.
  • isolation.rb — run each test in its own subprocess.
  • notification_assertions.rbassert_notifications_count, assert_no_notifications.
  • error_reporter_assertions.rb, event_reporter_assertions.rb.

ActiveSupport::TestCase (activesupport/lib/active_support/test_case.rb) is the base class for every *Test in Rails.

Integration points

  • Every other Rails component requires Active Support and registers Notifications subscribers via a LogSubscriber.
  • Rails::Application runs the :active_support lazy load hook so applications can extend Active Support without holding direct references at boot.
  • ActiveSupport::Railtie (in activesupport/lib/active_support/railtie.rb) wires up cache stores, time zone defaults, and the message verifier from application configuration.

Entry points for modification

  • Adding a core extension: create a new file under core_ext/<class>/ and require it from the relevant core_ext/<class>.rb aggregator. Add a test under test/core_ext/.
  • Adding a cache store: subclass ActiveSupport::Cache::Store and register via ActiveSupport::Cache.lookup_store(:my_store). Tests live in test/cache/.
  • Adding to the testing toolkit: add a module under testing/ and include it from ActiveSupport::TestCase.
  • Adding a notification event: publish via ActiveSupport::Notifications.instrument("name.namespace", payload) and update the relevant component's LogSubscriber to pretty-print it.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Active Support – Ruby on Rails wiki | Factory