Sha256: 8751e42f6a0ba47a9d42434cf9fa6df179f41884c960f72822aa866b6692f63f

Contents?: true

Size: 1.25 KB

Versions: 6

Compression:

Stored size: 1.25 KB

Contents

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

class Unidom::Party::Collaborating < Unidom::Party::ApplicationRecord

  self.table_name = 'unidom_collaboratings'

  include Unidom::Common::Concerns::ModelExtension

  validates :name, presence: true, length: { in: 2..self.columns_hash['name'].limit }

  belongs_to :collaboration, polymorphic: true
  belongs_to :collaborator,  polymorphic: true

  scope :collaboration_is, ->(collaboration) { where collaboration: collaboration }
  scope :collaborated_by,  ->(collaborator)  { where collaborator:  collaborator  }

  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

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
unidom-party-1.8.3 app/models/unidom/party/collaborating.rb
unidom-party-1.8.2 app/models/unidom/party/collaborating.rb
unidom-party-1.8.1 app/models/unidom/party/collaborating.rb
unidom-party-1.8 app/models/unidom/party/collaborating.rb
unidom-party-1.7.2 app/models/unidom/party/collaborating.rb
unidom-party-1.7.1 app/models/unidom/party/collaborating.rb