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 ¶
- Variables
- func AggregateImportPaths() []string
- func Autoloaders() any
- func BacktraceCleaner() any
- func BuildVersion(importPath string) (version string, ok bool)
- func Cache() any
- func ComponentVersion(c Component) (version string, ok bool)
- func Configuration() any
- func Count() int
- func Error() any
- func GemVersion() string
- func Groups(extra ...string) []string
- func GroupsWith(conditional map[string][]string, extra ...string) []string
- func ImportPaths() []string
- func Logger() any
- func PublicPath() string
- func Root() string
- func SetApplication(app App)
- func SetCache(c any)
- func SetLogger(l any)
- func Version() string
- type App
- type Component
- type EnvironmentInquirer
- type StringInquirer
- type VersionNumber
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 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 ¶
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 ¶
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`.
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 (Component) ImportPath ¶
ImportPath returns the Go module / import path, for example "github.com/go-ruby-activesupport/activesupport".
func (Component) LandingURL ¶
LandingURL returns the component's landing-site 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 ¶
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.
