rails

package module
v0.0.0-...-cb01663 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

README

go-ruby-rails/rails

rails — go-ruby-rails

Docs License Go Coverage

A pure-Go (no cgo) reimplementation of the Ruby on Rails rails meta-gem — targeting Rails 8.1.x on MRI 4.0.5, the same fidelity basis every go-ruby-* framework component is validated against.

In Ruby, rails ships almost no code of its own. It is the meta-gem: it declares a dependency on each framework component (ActiveSupport, ActiveModel, ActiveJob, ActionPack, ActionView, ActionMailer, ActionCable, ActiveStorage, Railties) and provides the top-level Rails moduleRails.application, Rails.env, Rails.root, Rails.logger, Rails.cache, Rails.configuration, and the Rails::VERSION constant. This package mirrors exactly that role, with no Ruby runtime.

It is the rails backend for go-embedded-ruby and a standalone, reusable Go module — the capstone that ties the go-ruby-* Rails family together.

What it ties together

The framework components are independent, MRI-faithful, pure-Go modules, each under its own github.com/go-ruby-<name>/<name> organization. This meta-gem carries a machine-readable manifest of them and a blank-import aggregate:

Component Ruby gem go-ruby-* module In rails/all
activesupport ActiveSupport go-ruby-activesupport/activesupport
activemodel ActiveModel go-ruby-activemodel/activemodel
activejob ActiveJob go-ruby-activejob/activejob
actionpack ActionPack go-ruby-actionpack/actionpack
actionview ActionView go-ruby-actionview/actionview
actioncable ActionCable go-ruby-actioncable/actioncable
activestorage ActiveStorage go-ruby-activestorage/activestorage
actionmailer ActionMailer go-ruby-actionmailer/actionmailer
railties Rails::Railtie go-ruby-railties/railties

The manifest is the single source of truth: Components(), AvailableComponents(), Lookup(name), ImportPaths(), and AggregateImportPaths() derive every component's org, import path, and site URLs from its name, so the catalog cannot drift. Every catalogued component has shipped, so all are Available = true and blank-imported by rails/all; a test keeps the manifest and the aggregate exactly in sync.

The Rails module

import "github.com/go-ruby-rails/rails"

rails.VERSION            // VersionNumber{Major: 8, Minor: 1, Tiny: 3}
rails.Version()          // "8.1.3"   — Rails.version
rails.GemVersion()       // "8.1.3"   — Rails.gem_version

rails.SetEnv("production")
rails.Env().Is("production") // true  — Rails.env.production?
rails.Env().Local()          // false — Rails.env.local? (development || test)

rails.Groups()                            // ["default", "production"]
rails.GroupsWith(map[string][]string{     // Rails.groups(assets: %w[development test])
    "assets": {"development", "test"},
})

rails.SetApplication(app) // app satisfies rails.App (go-ruby-railties provides it)
rails.Root()              // Rails.root          (delegates to app)
rails.Configuration()     // Rails.configuration (delegates to app)
rails.Autoloaders()       // Rails.autoloaders   (delegates to app)
rails.PublicPath()        // Rails.public_path   (delegates to app)
rails.Cache()             // Rails.cache         (override, else app store)
rails.Logger()            // Rails.logger
rails.BacktraceCleaner()  // Rails.backtrace_cleaner
rails.Error()             // Rails.error

Rails.env returns an EnvironmentInquirer — the pure-Go equivalent of ActiveSupport::EnvironmentInquirer — so Env().Is("production") mirrors Rails.env.production?. The accessors that expose application state delegate to the App set via SetApplication; without a booted application they return the same empty/zero result the Ruby methods return before boot. The concrete application type is owned by go-ruby-railties — the meta-gem stays decoupled from it through the small App interface.

The rails/all aggregate

import _ "github.com/go-ruby-rails/rails/all"

blank-imports every shipped component, so a single go get github.com/go-ruby-rails/rails and one import pull the whole pure-Go Rails stack into your build graph. Building rails/all is also the family's integration proof: it compiles every component together, at its pinned pseudo-version, on every supported architecture.

ComponentVersion(c) reports the exact version each component was pinned to in the running binary's build graph (read from the embedded build info).

Tests & coverage

The package holds 100% line coverage (version, env inquirer, groups, the module accessors, and the manifest — the external application state is exercised through a fake App and a getenv seam), gated in CI. Everything, including the rails/all aggregate, cross-compiles on all six supported 64-bit targets: amd64, arm64, riscv64, loong64, ppc64le, and s390x.

$ go test -race -cover ./...
ok  github.com/go-ruby-rails/rails  coverage: 100.0% of statements

License

BSD-3-Clause — see LICENSE. Copyright (c) 2026, the go-ruby-rails/rails authors.

WebAssembly

Being pure Go (CGO=0), this library also compiles to WebAssembly — both GOOS=js GOARCH=wasm (browser / Node.js) and GOOS=wasip1 GOARCH=wasm (WASI). CI builds both targets on every push, alongside the six 64-bit native/qemu arches.

GOOS=js     GOARCH=wasm go build ./...   # browser / Node
GOOS=wasip1 GOARCH=wasm go build ./...   # WASI (wasmtime, wasmer, wasmedge, …)

Documentation

Overview

Package rails is the pure-Go (no cgo), MRI-faithful reimplementation of the Ruby on Rails meta-gem: the `rails` gem itself.

In Ruby, the `rails` gem ships almost no code of its own. It is the meta-gem that ties the framework's components together — it declares a dependency on each of them (ActiveSupport, ActiveModel, ActiveJob, ActionPack, ActionView, ActionMailer, ActionCable, ActiveStorage, Railties, ...) and provides the top-level Rails module: Rails.application, Rails.env, Rails.root, Rails.logger, Rails.cache, Rails.configuration, and the Rails::VERSION constant. This package mirrors exactly that role.

The version

VERSION is the Rails release this family targets — 8.1.x on MRI 4.0.5, the same fidelity basis every sibling component is validated against. Version and GemVersion return its dotted string form, mirroring Rails.version and Rails.gem_version.

The top-level Rails module

The module-level accessors — Application, Env, Root, Logger, Cache, Configuration, BacktraceCleaner, Autoloaders, Groups, PublicPath, Error — mirror the singleton methods on Ruby's Rails module. The ones that expose application state (Root, Configuration, Autoloaders, PublicPath, Cache) delegate to the Application set via SetApplication, which the go-ruby-railties Application object will satisfy; without an application they return the same empty/zero result the Ruby methods return before boot.

Env returns an EnvironmentInquirer — the pure-Go equivalent of ActiveSupport::EnvironmentInquirer — so Env().Is("production") mirrors Rails.env.production? and Env().Local() mirrors Rails.env.local?.

The component manifest

Components is the machine-readable catalog of the framework's components: each Component carries its gem name and derives its go-ruby-* organization, import path, and site URLs. The github.com/go-ruby-rails/rails/all sub-package blank-imports every shipped component, so

go get github.com/go-ruby-rails/rails
import _ "github.com/go-ruby-rails/rails/all"

pulls the whole pure-Go Rails stack into a consumer's build graph behind one dependency, and building it cross-compiles the entire framework on every supported architecture.

Index

Constants

This section is empty.

Variables

View Source
var VERSION = VersionNumber{Major: 8, Minor: 1, Tiny: 3, Pre: ""}

VERSION is the Rails release this family targets: 8.1.x on MRI 4.0.5, the fidelity basis shared by every go-ruby-* framework component.

Functions

func AggregateImportPaths

func AggregateImportPaths() []string

AggregateImportPaths returns the Go import paths blank-imported by the rails/all aggregate — the available components only — sorted. A test keeps all/all.go exactly in sync with this list.

func Autoloaders

func Autoloaders() any

Autoloaders returns the application's autoloader set, mirroring Rails.autoloaders. It is nil when no application is registered.

func BacktraceCleaner

func BacktraceCleaner() any

BacktraceCleaner returns the shared backtrace cleaner, mirroring Rails.backtrace_cleaner. It is created on first use and memoized. The concrete object is owned by ActiveSupport, so it is returned as an opaque value.

func BuildVersion

func BuildVersion(importPath string) (version string, ok bool)

BuildVersion is ComponentVersion keyed by import path.

func Cache

func Cache() any

Cache returns the Rails cache store, mirroring Rails.cache. An explicit store set with SetCache takes precedence; otherwise the application's configured store is used; without either it is nil.

func ComponentVersion

func ComponentVersion(c Component) (version string, ok bool)

ComponentVersion returns the version a framework component's module was pinned to in the build graph of the running binary, if that module is present.

The version is only available when the component is actually part of the binary's build graph — for example because the binary imports the rails/all aggregate, or imports the component directly. When it is not present, or when the binary was built without module information, ok is false.

func Configuration

func Configuration() any

Configuration returns the application's configuration, mirroring Rails.configuration. It is nil when no application is registered.

func Count

func Count() int

Count reports the number of framework components in the manifest.

func Error

func Error() any

Error returns the shared error reporter, mirroring Rails.error (which delegates to ActiveSupport.error_reporter). It is created on first use and memoized. The concrete object is owned by ActiveSupport, so it is returned as an opaque value.

func GemVersion

func GemVersion() string

GemVersion returns the Rails release as a dotted string, mirroring Rails.gem_version.

func Groups

func Groups(extra ...string) []string

Groups returns the ordered, de-duplicated list of groups active in the current environment, mirroring Rails.groups(*groups).

The result is `default`, then the current environment, then any positional extras, then the comma-separated RAILS_GROUPS environment variable — with empty entries dropped and duplicates removed (keeping first occurrence).

func GroupsWith

func GroupsWith(conditional map[string][]string, extra ...string) []string

GroupsWith is Groups with the conditional-hash form of Rails.groups: for each key in conditional whose value contains the current environment, the key is appended to the group list. This mirrors, for example, `Rails.groups(assets: %w(development test))`. Keys are considered in sorted order so the result is deterministic.

func ImportPaths

func ImportPaths() []string

ImportPaths returns the Go import path of every component in the manifest, sorted.

func Logger

func Logger() any

Logger returns the Rails logger, mirroring Rails.logger. It is nil until one is set.

func PublicPath

func PublicPath() string

PublicPath returns the application's public directory, mirroring Rails.public_path. It is the empty string when no application is registered (Ruby returns nil).

func Root

func Root() string

Root returns the application's root directory, mirroring Rails.root. It is the empty string when no application is registered (Ruby returns nil).

func SetApplication

func SetApplication(app App)

SetApplication registers the running application, mirroring `Rails.application = app`. Passing nil clears it.

func SetCache

func SetCache(c any)

SetCache sets the Rails cache store, mirroring `Rails.cache = store`.

func SetLogger

func SetLogger(l any)

SetLogger sets the Rails logger, mirroring `Rails.logger = logger`.

func Version

func Version() string

Version returns the Rails release as a dotted string, mirroring Rails.version (which returns a Gem::Version built from Rails::VERSION::STRING).

Types

type App

type App interface {
	// Root is the application's root directory (config.root), a filesystem path.
	Root() string
	// Config is the application's configuration object (application.config).
	Config() any
	// Autoloaders is the application's autoloader set (application.autoloaders).
	Autoloaders() any
	// PublicPath is the first entry of paths["public"].
	PublicPath() string
	// Cache is the configured cache store (config.cache_store instance).
	Cache() any
}

App is the minimal surface of the Rails application object that the top-level Rails module delegates to. In Ruby this is a Rails::Application (a Railtie) instance; the meta-gem never constructs one — go-ruby-railties owns the concrete type. Modelling it as an interface here keeps the meta-gem decoupled from railties while still letting the delegating accessors (Root, Configuration, Autoloaders, PublicPath, Cache) forward to it.

The configuration, autoloader set, and cache store are opaque to the meta-gem (owned by railties and the components), so they are typed as any — exactly as Ruby's Rails.configuration simply returns application.config.

func Application

func Application() App

Application returns the registered application, mirroring Rails.application. It is nil until SetApplication is called (before the app boots).

type Component

type Component struct {
	// Name is the gem / repository name, for example "activesupport". It is both
	// the go-ruby-* org suffix and the Go module name.
	Name string
	// Gem is the Ruby constant the component provides, for example
	// "ActiveSupport".
	Gem string
	// Description is a one-line summary of the component's responsibility.
	Description string
	// Available reports whether the go-ruby-* component has shipped and is
	// therefore blank-imported by the rails/all aggregate. Components whose
	// go-ruby-* repository is still empty are catalogued with Available=false.
	Available bool
}

Component describes one component of the Rails framework: a pure-Go, MRI-faithful reimplementation of one of the gems the `rails` meta-gem ties together (ActiveSupport, ActionPack, ...).

The organization, import path, and site URLs are not stored — they follow the go-ruby-* family's uniform convention and are derived from Name, so the manifest cannot drift out of sync with them.

func AvailableComponents

func AvailableComponents() []Component

AvailableComponents returns the components that have shipped and are included in the rails/all aggregate, sorted by Name.

func Components

func Components() []Component

Components returns every framework component in the manifest, sorted by Name. The returned slice is a copy; mutating it cannot affect the manifest.

func Lookup

func Lookup(name string) (Component, bool)

Lookup returns the component with the given Name.

func (Component) DocsURL

func (c Component) DocsURL() string

DocsURL returns the component's documentation-site URL.

func (Component) ImportPath

func (c Component) ImportPath() string

ImportPath returns the Go module / import path, for example "github.com/go-ruby-activesupport/activesupport".

func (Component) LandingURL

func (c Component) LandingURL() string

LandingURL returns the component's landing-site URL.

func (Component) Org

func (c Component) Org() string

Org returns the GitHub organization that owns the component, for example "go-ruby-activesupport".

func (Component) RepoURL

func (c Component) RepoURL() string

RepoURL returns the canonical source-repository URL.

type EnvironmentInquirer

type EnvironmentInquirer struct {
	StringInquirer
}

EnvironmentInquirer is the pure-Go equivalent of ActiveSupport::EnvironmentInquirer, the StringInquirer subclass Rails uses for Rails.env. It adds the environment-specific EnvironmentInquirer.Local predicate on top of the generic StringInquirer.Is.

func Env

func Env() EnvironmentInquirer

Env returns the current environment as an EnvironmentInquirer, mirroring Rails.env. On first use the value is resolved from RAILS_ENV, then RACK_ENV, then defaults to "development", and is memoized thereafter (as in Rails).

func NewEnvironmentInquirer

func NewEnvironmentInquirer(name string) EnvironmentInquirer

NewEnvironmentInquirer wraps name in an EnvironmentInquirer.

func SetEnv

func SetEnv(name string) EnvironmentInquirer

SetEnv overrides the current environment, mirroring `Rails.env = "production"`. It returns the new inquirer.

func (EnvironmentInquirer) Local

func (e EnvironmentInquirer) Local() bool

Local reports whether the environment is one of the built-in local environments — "development" or "test" — mirroring Rails.env.local?.

type StringInquirer

type StringInquirer struct {
	// contains filtered or unexported fields
}

StringInquirer is the pure-Go equivalent of ActiveSupport::StringInquirer: a string wrapper whose predicate queries compare against the wrapped value, so that in Ruby `env.production?` is true exactly when the string equals "production". Here that predicate is spelled StringInquirer.Is; the rbgo binding maps the dynamic `name?` methods onto it.

The value is immutable, mirroring the frozen string Rails wraps.

func NewStringInquirer

func NewStringInquirer(value string) StringInquirer

NewStringInquirer wraps value in a StringInquirer.

func (StringInquirer) Is

func (si StringInquirer) Is(name string) bool

Is reports whether the wrapped value equals name, mirroring the dynamic `name?` predicate (`env.production?` == `env == "production"`).

func (StringInquirer) String

func (si StringInquirer) String() string

String returns the wrapped string, so a StringInquirer is usable anywhere the plain value is (mirroring StringInquirer < String).

type VersionNumber

type VersionNumber struct {
	Major int
	Minor int
	Tiny  int
	Pre   string
}

VersionNumber is the structured Rails release number, the pure-Go equivalent of Ruby's Rails::VERSION module. Major, Minor, and Tiny mirror the MAJOR, MINOR, and TINY constants; Pre mirrors PRE (empty when the release is final).

func (VersionNumber) STRING

func (v VersionNumber) STRING() string

STRING returns the dotted release string, mirroring Rails::VERSION::STRING, which is [MAJOR, MINOR, TINY, PRE].compact.join("."). The pre-release segment is appended only when present.

func (VersionNumber) String

func (v VersionNumber) String() string

String implements fmt.Stringer with the same dotted form as VersionNumber.STRING.

Directories

Path Synopsis
Package all blank-imports every shipped component of the Rails framework, so that a single
Package all blank-imports every shipped component of the Rails framework, so that a single

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL