Sha256: 360992e222dda1834194e83827f986eab5f508db7b5d78a66e218187717a32ad

Contents?: true

Size: 818 Bytes

Versions: 3

Compression:

Stored size: 818 Bytes

Contents

module Saucy
  module Project
    extend ActiveSupport::Concern

    included do
      belongs_to :account
      has_many :project_memberships, :dependent => :destroy
      has_many :users, :through => :project_memberships

      validates_presence_of :account_id

      after_create :assign_default_memberships
    end

    module ClassMethods
      def visible_to(user)
        where(['projects.id IN(?)', user.project_ids])
      end

      def by_name
        order("projects.name")
      end
    end

    module InstanceMethods
      def has_member?(user)
        project_memberships.exists?(:user_id => user.id)
      end

      private

      def assign_default_memberships
        account.admins.each do |admin|
          self.project_memberships.create(:user => admin)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
saucy-0.1.3 lib/saucy/project.rb
saucy-0.1.2 lib/saucy/project.rb
saucy-0.1.1 lib/saucy/project.rb