$ show carrierwaveuploader/carrierwave
CarrierWave is a mature Ruby gem that provides file upload capabilities to Ruby web applications, primarily Rails. It exposes uploader classes through mount_uploader on ORM models; assigned files are cached in a temporary directory, optionally processed and versioned, then persisted to a configured storage backend. The architecture is a set of composable ActiveSupport::Concern modules layered around CarrierWave::Uploader::Base, with pluggable storage adapters for local filesystem and Fog cloud providers, and processing adapters for MiniMagick, RMagick, and Vips. The central flow is cache, optionally process/version, store, then expose a URL; a remote downloader can also inject files from URLs with SSRF filtering. Production behavior is backed by a large RSpec suite and Cucumber features. It supports single and multiple uploads, metadata columns, direct-to-cloud uploads, cache cleanup, and ActiveRecord callbacks including after_commit deletion and rollback handling. External dependencies are limited to ActiveSupport/ActiveModel, Marcel for MIME detection, ssrf_filter for download safety, and optional Fog/image processor gems. This is not a standalone application or service; it is embedded into host applications as a library dependency. Maintenance is active, with ongoing 4.0.0.rc development and a Rails version matrix. Technical drift is moderate: the codebase still supports Ruby 2.7, contains a permissive RuboCop configuration, legacy scripts, and several deprecation layers, but the core abstractions are current and extensively tested.
The LLM identified 5 files worth highlighting for reuse:
Implements the uploader version system: each version is a dynamically built subclass with its own processing steps, storage path, filename rules, and conditional activation. Uses thread-safe lazy construction and nested version composition. This pattern is reusable in any content-derivative system requiring on-demand, configurable transformations.
Encapsulates downloading a remote file into an uploader. Normalizes and validates URLs, filters SSRF vectors via ssrf_filter, supports redirects, retries with backoff, custom headers, and user-provided downloader overrides. The pipeline is self-contained and demonstrates a safe remote-fetch abstraction.
Unifies File, Tempfile, StringIO, and path-string inputs into a single object with move/copy/delete operations, filename sanitization for traversal, NUL bytes, and invalid encoding, and content-type detection via Marcel. Could be extracted into any Ruby project needing secure file-handling primitives.
Provides an add_config DSL that generates inheritable class-level and instance-level accessors for uploader options, with support for default values, procs, and deprecated keys. This is a compact, reusable way to propagate configuration through an inheritance hierarchy.
Defines the interface contract for storage engines: store!, retrieve!, cache!, materialize_cache!, direct_upload_url, and clean_cache!. The local File and cloud Fog backends implement this interface, making the storage layer swappable without changing uploader code. A clean example of an adapter pattern.