Module: Inertia

Defined in:
lib/inertia/props.rb,
lib/inertia/rspec.rb,
lib/inertia/inertia.rb,
lib/inertia/version.rb,
lib/inertia/frontend.rb,
lib/inertia/renderer.rb,
lib/inertia/configuration.rb,
lib/inertia/rage_extension.rb,
lib/inertia/request_context.rb,
lib/inertia/vite_dev_server.rb,
lib/inertia/protocol_builder.rb,
lib/inertia/middleware/assets.rb,
lib/inertia/controller_helpers.rb,
lib/inertia/middleware/version.rb,
lib/inertia/_codex_protocol_builder.rb

Defined Under Namespace

Modules: ControllerHelpers, Middleware, Props, RSpec Classes: Configuration, Frontend, ProtocolBuilder, RageExtension, Renderer, RequestContext, ViteDevServer

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.configConfiguration

Returns the global configuration instance.

Returns:



39
40
41
# File 'lib/inertia/inertia.rb', line 39

def self.config
  @config ||= Configuration.new
end

.configure { ... } ⇒ Object

Configures the Inertia integration using a block.

The block is evaluated in the context of the Configuration instance, allowing direct access to configuration setters.

Examples:

Inertia.configure do |config|
  config.frontend_path = "client"
  config.build_on_start = false

  config.dev_server.host = "0.0.0.0"
  config.dev_server.port = 3000
end

Yields:

  • Evaluates the block in the configuration context



32
33
34
# File 'lib/inertia/inertia.rb', line 32

def self.configure
  yield config
end

.deferred(group: "default") { ... } ⇒ Props::Deferred

Creates a deferred prop that will be loaded in a subsequent request after the initial page load.

Examples:

render inertia: "Users/Index", props: {
  users: Inertia.deferred { User.all }
}

Parameters:

  • group (String) (defaults to: "default")

    the group name for batching deferred props together

Yields:

  • the block that returns the prop value when evaluated

Returns:



52
53
54
# File 'lib/inertia/inertia.rb', line 52

def self.deferred(group: "default", &block)
  Props::Deferred.new(group:, block:)
end

.once(key: nil, fresh: false, expires_in: nil) { ... } ⇒ Props::Once

Creates a prop that is evaluated only once and cached by the frontend.

Examples:

render inertia: "Dashboard", props: {
  stats: Inertia.once(expires_in: 300) { Stats.calculate }
}

Parameters:

  • key (String, nil) (defaults to: nil)

    a unique cache key for the prop (auto-generated if nil)

  • fresh (Boolean) (defaults to: false)

    forces re-evaluation when true

  • expires_in (Integer, ActiveSupport::Duration, nil) (defaults to: nil)

    cache expiration time in seconds

Yields:

  • the block that returns the prop value when evaluated

Returns:



67
68
69
# File 'lib/inertia/inertia.rb', line 67

def self.once(key: nil, fresh: false, expires_in: nil, &block)
  Props::Once.new(key:, fresh:, expires_in:, block:)
end

.optional { ... } ⇒ Props::Optional

Creates a prop that is only included when explicitly requested by the client.

Examples:

render inertia: "Users/Show", props: {
  user: user,
  permissions: Inertia.optional { user.permissions }
}

Yields:

  • the block that returns the prop value when evaluated

Returns:



80
81
82
# File 'lib/inertia/inertia.rb', line 80

def self.optional(&block)
  Props::Optional.new(block:)
end