Class: Collavre::Topic
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- ApplicationRecord
- Collavre::Topic
- Defined in:
- app/models/collavre/topic.rb
Instance Method Summary collapse
- #archive! ⇒ Object
- #archived? ⇒ Boolean
-
#primary_agent ⇒ Object
Returns the primary agent User for this topic (from orchestration policy).
-
#set_primary_agent!(agent) ⇒ Object
Sets or replaces the primary agent for this topic.
- #unarchive! ⇒ Object
Instance Method Details
#archive! ⇒ Object
57 58 59 |
# File 'app/models/collavre/topic.rb', line 57 def archive! update!(archived_at: Time.current) end |
#archived? ⇒ Boolean
53 54 55 |
# File 'app/models/collavre/topic.rb', line 53 def archived? archived_at.present? end |
#primary_agent ⇒ Object
Returns the primary agent User for this topic (from orchestration policy)
25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/collavre/topic.rb', line 25 def primary_agent policy = OrchestratorPolicy.find_by( policy_type: "arbitration", scope_type: "Topic", scope_id: id ) return nil unless policy&.config&.dig("primary_agent_id") User.find_by(id: policy.config["primary_agent_id"]) end |
#set_primary_agent!(agent) ⇒ Object
Sets or replaces the primary agent for this topic
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/collavre/topic.rb', line 37 def set_primary_agent!(agent) policy = OrchestratorPolicy.find_or_initialize_by( policy_type: "arbitration", scope_type: "Topic", scope_id: id ) policy.update!( config: { "strategy" => "primary_first", "primary_agent_id" => agent.id }, priority: 10, enabled: true ) end |
#unarchive! ⇒ Object
61 62 63 |
# File 'app/models/collavre/topic.rb', line 61 def unarchive! update!(archived_at: nil) end |