class RailsAiAdmin::Selections::Builder
Captures exact scoped targets; never saves a query to expand during execution.
Constants
- LIMIT
- Snapshot
- Target
Public Instance Methods
Source
# File lib/rails_ai_admin/selections/builder.rb, line 13 def capture(context:, resource:, target_ids:) access = Authorization::Access.new(context, resource) raise AccessDenied unless RailsAiAdmin.registry.fetch(resource.key).equal?(resource) ensure_storage!(resource) targets = ActiveRecord::Base.while_preventing_writes do access.authorize_selection! ids = canonical_ids(resource, target_ids) records = scoped_records(access, ids) records.map { |record| target(access, record) }.sort_by(&:id).freeze end version = resource_version(resource) selection = Selection.transaction(requires_new: true) do row = Selection.create!(id: SecureRandom.uuid, actor_ref: context.actor_ref, tenant_ref: context.tenant_ref, security_version: context.security_version, resource_key: resource.key.to_s, resource_version: version, manifest_digest: manifest_digest(version, targets), item_count: targets.size, expires_at: Time.current + RailsAiAdmin.configuration.intent_ttl) SelectionItem.insert_all!(targets.each_with_index.map { |item, position| { selection_id: row.id, target_id: item.id, expected_version: item.expected_version, position: position } }) row end raise ConfigurationError, "Selection creation was rolled back" unless selection snapshot(selection, targets) rescue ActiveRecord::ReadOnlyError raise ConfigurationError, "Selection lookup must be read-only", cause: nil end
Source
# File lib/rails_ai_admin/selections/builder.rb, line 42 def revalidate(context:, selection_ref:, resource: nil, manifest_digest: nil, &block) read_snapshot(context: context, selection_ref: selection_ref, resource: resource, manifest_digest: manifest_digest, labels: true, &block) end
This is a fresh check, not a lock or authorization for a later write. Execution must bind this digest and recheck each item in its transaction. A block receives each current record, inside the same read-only check.
Source
# File lib/rails_ai_admin/selections/builder.rb, line 48 def validate_for_admission(context:, selection_ref:, resource:, manifest_digest:, &authorize_target) read_snapshot(context: context, selection_ref: selection_ref, resource: resource, manifest_digest: manifest_digest, labels: false, &authorize_target) end
Internal admission path: no title projection or domain preflight under the parent lock. Only exact target checks and the given authorization run.