← docs.speechwave.live

Elixir glossary

Terms you'll encounter in the Speechwave codebase. Ruby equivalents noted where helpful.

Language fundamentals

Atom
A constant whose name is its value: :ok, :error, true. Ruby: same concept, same syntax.
Pattern matching
The = operator doesn't assign, it matches the left side against the right. {:ok, result} = {:ok, 42} binds result to 42. If sides don't match, it raises MatchError. Ruby: no equivalent, closest is destructuring in JS.
Pin operator (^)
Forces a variable to be matched against its existing value rather than rebound. ^x = 5 asserts that x is 5.
Pipe operator (|>)
Passes the result of the left expression as the first argument to the function on the right. data |> transform() |> save(). Ruby: like method chaining, but for free functions.
Guard clause
A when condition on a function head that restricts when that clause matches: def foo(x) when is_integer(x).
Sigil
A ~ prefix for literal syntax: ~r/regex/, ~w(word list), ~T[12:00:00].
Struct
A map with a fixed set of keys and a name, defined with defstruct. %Talk{slug: "demo"}. Ruby: like Struct.new(:slug) but enforced at compile time.

Modules & functions

Module
A namespace for functions, defined with defmodule. No instances, no state. Ruby: like a module with only class methods, no self state.
def / defp
Public / private function. Multiple clauses of the same function with different patterns are tried top-to-bottom.
use
Injects code from another module via its __using__/1 macro. use GenServer gives you GenServer callbacks. Ruby: like include but can rewrite the including module.
import
Brings functions from another module into scope so you can call them without the module prefix. import Ecto.Query.
alias
Creates a shortcut name for a module. alias Speechwave.Talks.Talk lets you write Talk instead of the full path.
@ (module attribute)
A compile-time constant or annotation: @moduledoc, @impl true. Ruby: no direct equivalent, partly like class-level constants.

Phoenix & LiveView

Socket / socket.assigns
The LiveView state container. assign(socket, key: value) stores data; templates access it as @key. Ruby/Rails: like instance variables in a controller, but immutable, you return a new socket.
mount/3
Called when a LiveView starts. Sets up initial assigns. Returns {:ok, socket}.
handle_event/3
Handles a user action from the browser (click, form submit). Returns {:noreply, socket}.
handle_info/2
Handles messages from other processes (PubSub broadcasts, timer ticks). Returns {:noreply, socket}.
Context module
A module that groups related database operations: Speechwave.Talks, Speechwave.Accounts. Phoenix convention for organizing business logic. Ruby/Rails: like a Service Object or the Model layer, but explicitly a module of functions.
Changeset
An Ecto struct that tracks proposed changes to data, with validations. You build one, then pass it to Repo.insert/update. Ruby/Rails: like ActiveRecord validations, but the validation result is a separate data structure from the record.
Scope
A Speechwave-specific pattern: %Scope{user: user} wraps the authenticated user so context functions always filter by owner.
Plug
A composable middleware module or function. Plugs are chained in pipelines to process HTTP requests. Ruby/Rails: like Rack middleware.
Pipeline
A named sequence of plugs in the router: pipeline :browser do ... end.

OTP (just enough)

Process
A lightweight, isolated unit of concurrency managed by the BEAM VM. Not an OS process. Thousands can run simultaneously.
Supervisor
A process that monitors child processes and restarts them on failure. Defined in application.ex.
GenServer
A generic server process with a standard interface (call/cast/info). Speechwave's RateLimiter and AuthThrottle are GenServers.
PubSub
Publish-subscribe messaging between processes. Phoenix uses it to push updates to LiveViews in real time.