Sha256: 0212d77c91a14857f6bfd582acd7f70e44dd809e464794ea0ad004dd6385d257

Contents?: true

Size: 1.16 KB

Versions: 19

Compression:

Stored size: 1.16 KB

Contents

module Unidom::Party::Concerns::AsCollaborator

  extend ActiveSupport::Concern

  included do |includer|

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

    def collaborate!(on: nil, as: nil, at: Time.now, name: nil, priority: 0, grade: 0)
      collaborating = collaboratings.collaboration_is(on).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! collaboration: on, role_code: as, name: name, priority: priority, grade: grade, opened_at: at
      end
      collaborating
    end

    def collaborate?(on: nil, as: nil, at: Time.now, priority: nil, grade: nil)
      query = collaboratings
      query = query.collaboration_is on       if on.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_collaborator.rb
unidom-party-1.9.8 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.9.7 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.9.6 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.9.5 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.9.4 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.9.3 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.9.2 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.9.1 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.9 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.8.5 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.8.4 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.8.3 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.8.2 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.8.1 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.8 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.7.2 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.7.1 app/models/unidom/party/concerns/as_collaborator.rb
unidom-party-1.7 app/models/unidom/party/concerns/as_collaborator.rb