Class: Unidom::Party::Collaborating

Inherits:
ApplicationRecord show all
Includes:
Common::Concerns::ModelExtension
Defined in:
app/models/unidom/party/collaborating.rb

Overview

Collaborating 是参与者以特定的角色进行协作。

Class Method Summary collapse

Class Method Details

.collaborate!(collaboration: nil, collaborator: nil, name: collaborator.try(:name), role_code: nil, priority: 1, grade: 1, description: nil, instruction: nil, opened_at: Time.now) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/unidom/party/collaborating.rb', line 18

def self.collaborate!(collaboration: nil, collaborator: nil, name: collaborator.try(:name), role_code: nil, priority: 1, grade: 1, description: nil, instruction: nil, opened_at: Time.now)
  query         = collaboration_is(collaboration).collaborated_by(collaborator).role_coded_as(role_code).valid_at(now: opened_at).alive
  attributes    = { name: name, priority: priority, grade: grade, description: description, instruction: instruction }
  collaborating = query.first_or_initialize attributes
  if collaborating.new_record?
    collaborating.opened_at = opened_at
  else
    collaborating.attributes = attributes
  end
  collaborating.save!
  collaborating
end