Sha256: a4dc727070de895033579032963d0141c5dcb946530c03aaa665d7f24a36655a

Contents?: true

Size: 1.16 KB

Versions: 19

Compression:

Stored size: 1.16 KB

Contents

module Unidom::Party::Concerns::AsCollaboration

  extend ActiveSupport::Concern

  included do |includer|

    has_many :collaboratings, class_name: 'Unidom::Party::Collaborating', as: :collaboration

    def is_collaborated!(by: nil, as: nil, at: Time.now, name: nil, priority: 0, grade: 0)
      collaborating = collaboratings.collaborated_by(by).role_coded_as(as).valid_at(now: at).alive.first
      if collaborating.present?
        collaborating.attributes = { name: name, priority: priority, grade: grade }
        collaborating.save!
      else
        collaborating = collaboratings.create! collaborator: by, role_code: as, name: name, priority: priority, grade: grade, opened_at: at
      end
      collaborating
    end

    def is_collaborated?(by: nil, as: nil, at: Time.now, priority: nil, grade: nil)
      query = collaboratings
      query = query.collaborated_by by       if by.present?
      query = query.role_coded_as   as       if as.present?
      query = query.priority_is     priority if priority.present?
      query = query.grade_is        grade    if grade.present?
      query.valid_at(now: at).alive.exists?
    end

  end

  module ClassMethods
  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
unidom-party-2.0 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9.8 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9.7 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9.6 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9.5 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9.4 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9.3 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9.2 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9.1 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.9 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.8.5 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.8.4 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.8.3 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.8.2 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.8.1 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.8 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.7.2 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.7.1 app/models/unidom/party/concerns/as_collaboration.rb
unidom-party-1.7 app/models/unidom/party/concerns/as_collaboration.rb