Class: Ruact::Query
- Inherits:
-
Object
- Object
- Ruact::Query
- Defined in:
- lib/ruact/query.rb
Overview
Story 9.4 (route-driven redesign, Phase B) — base class for v2 server
QUERIES. Queries are plain classes under app/queries/; each public
instance method defined directly on the subclass is one query:
# app/queries/application_query.rb
class ApplicationQuery < Ruact::Query; end
# app/queries/catalog_query.rb
class CatalogQuery < ApplicationQuery
def categories
Category.active.pluck(:id, :name).map { |id, name| { value: id, label: name } }
end
def my_categories
current_user.categories.pluck(:id, :name)
end
end
# config/routes.rb
Rails.application.routes.draw do
ruact_queries CatalogQuery # GET /q/categories, GET /q/myCategories — visible in `rails routes`
end
Per the 2026-06-02 ADR addendum (Decision 2), dispatch goes through an
internal gem controller that inherits Ruact.config.query_parent_controller
(default ApplicationController) — the host's REAL callback chain
(authenticate_user!, tenant scoping, Pundit) runs BEFORE the query class
is instantiated (FR89). The query instance is fresh per request (NFR8) and
receives its execution context via the constructor, so
CatalogQuery.new(fake_context).categories is unit-testable with no Rails
boot.
The context accessors below are defined on Ruact::Query itself, so they
are INHERITED by subclasses — they never appear in a subclass's
public_instance_methods(false), which is exactly the set the
ruact_queries routing macro mounts (one named GET route per method).
Class Method Summary collapse
-
.__ruact_skipped_callbacks ⇒ Array<Array(Array<Symbol>, Hash)>
The recorded
(callbacks, options)pairs for this query class, consumed by ServerFunctions::QueryDispatch when the dispatch controller is generated. -
.ruact_skip_before_action(*callbacks, **options) ⇒ void
Story 9.4 AC4 / D1 — per-query callback opt-out (resolves ADR open item 1).
Instance Method Summary collapse
-
#current_user ⇒ Object?
The host's authenticated user, via the dispatching controller's own
current_user(Devise / Pundit / hand-rolled). -
#initialize(context) ⇒ Query
constructor
A new instance of Query.
-
#params ⇒ Object
The request params (query-string parameters on a GET).
-
#request ⇒ Object
The live request.
-
#session ⇒ Object
The host middleware's session.
Constructor Details
#initialize(context) ⇒ Query
Returns a new instance of Query.
45 46 47 |
# File 'lib/ruact/query.rb', line 45 def initialize(context) @__ruact_context = context end |
Class Method Details
.__ruact_skipped_callbacks ⇒ Array<Array(Array<Symbol>, Hash)>
The recorded (callbacks, options) pairs for this query class,
consumed by ServerFunctions::QueryDispatch when the dispatch
controller is generated. Per-class (not inherited) — a skip describes
the queries of the class that declares it.
102 103 104 |
# File 'lib/ruact/query.rb', line 102 def __ruact_skipped_callbacks @__ruact_skipped_callbacks ||= [] end |
.ruact_skip_before_action(*callbacks, **options) ⇒ void
This method returns an undefined value.
Story 9.4 AC4 / D1 — per-query callback opt-out (resolves ADR open
item 1). Mirrors Rails' skip_before_action ergonomics; the recorded
skips are applied verbatim to THIS query class's generated dispatch
controller when ruact_queries draws its routes, so the opt-out never
leaks to other query classes:
class PublicCatalogQuery < ApplicationQuery
ruact_skip_before_action :authenticate_user!
def categories = Category.pluck(:id, :name)
end
Options are forwarded to skip_before_action untouched — only: /
except: scope the skip to specific query methods (each method is one
controller action), raise: false tolerates a callback the parent
does not define.
91 92 93 94 |
# File 'lib/ruact/query.rb', line 91 def ruact_skip_before_action(*callbacks, **) __ruact_skipped_callbacks << [callbacks.map(&:to_sym), ] nil end |
Instance Method Details
#current_user ⇒ Object?
Returns the host's authenticated user, via the dispatching
controller's own current_user (Devise / Pundit / hand-rolled).
51 52 53 |
# File 'lib/ruact/query.rb', line 51 def current_user @__ruact_context.current_user end |
#params ⇒ Object
Returns the request params (query-string parameters on a GET).
56 57 58 |
# File 'lib/ruact/query.rb', line 56 def params @__ruact_context.params end |
#request ⇒ Object
Returns the live request.
61 62 63 |
# File 'lib/ruact/query.rb', line 61 def request @__ruact_context.request end |
#session ⇒ Object
Returns the host middleware's session.
66 67 68 |
# File 'lib/ruact/query.rb', line 66 def session @__ruact_context.session end |