Module: ActionAgent::Ownable
- Extended by:
- ActiveSupport::Concern
- Included in:
- Agent, ApiKey, ProviderKey, SandboxSession, SessionRecording
- Defined in:
- app/models/concerns/action_agent/ownable.rb
Overview
Attaches a dashboard record to whatever the host app calls an owner.
Each model names the associations that could own it, most preferred first, and the first one the host app has actually configured wins:
class Agent < ApplicationRecord
include Ownable
owned_by :user, :account
end
So an app with users scopes agents per user, an app with only accounts scopes them per account, and a single-user self-hosted install declares neither association and owns everything implicitly. That ordering is per-model on purpose: an app can reasonably keep agents per user while keeping API keys per account, and the platform does exactly that.
Both foreign keys exist in the engine's schema either way, so moving a deployment between shapes is a configuration change, not a migration.
Constant Summary collapse
- CLASS_FOR =
{ account: :account_class, user: :user_class }.freeze
Instance Method Summary collapse
-
#owner ⇒ Object
The record's owner under the current configuration, or nil.
-
#owner=(record) ⇒ Object
Assigns
ownerto whichever association this install uses.
Instance Method Details
#owner ⇒ Object
The record's owner under the current configuration, or nil.
74 75 76 77 |
# File 'app/models/concerns/action_agent/ownable.rb', line 74 def owner association = self.class.owner_association association && public_send(association) end |
#owner=(record) ⇒ Object
Assigns owner to whichever association this install uses. A no-op
when the host app configured no owner model.
81 82 83 84 |
# File 'app/models/concerns/action_agent/ownable.rb', line 81 def owner=(record) association = self.class.owner_association public_send(:"#{association}=", record) if association end |