Sha256: cacb38ffdfbb97c66f45bbbc0341408a74b40e0037894cfb6c07f86fd491b141

Contents?: true

Size: 658 Bytes

Versions: 7

Compression:

Stored size: 658 Bytes

Contents

class Role < ActiveRecord::Base

  belongs_to :user
  belongs_to :project

  validates :user_id, presence: true
  validates :project, presence: true

  class << self
    def to_users
      User.where(id: all.select(:user_id))
    end

    def to_projects
      Project.where(id: all.select(:project_id))
    end

    def for_user(user_or_id)
      user_id = user_or_id.is_a?(User) ? user_or_id.id : user_or_id
      where user_id: user_id
    end

    def for_project(project_or_id)
      project_id = project_or_id.is_a?(Project) ? project_or_id.id : project_or_id
      where project_id: project_id
    end

    def any?
      count > 0
    end
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
houston-core-0.8.4 app/models/role.rb
houston-core-0.8.3 app/models/role.rb
houston-core-0.8.2 app/models/role.rb
houston-core-0.8.1 app/models/role.rb
houston-core-0.8.0 app/models/role.rb
houston-core-0.8.0.pre2 app/models/role.rb
houston-core-0.8.0.pre app/models/role.rb