Sha256: 6e8c3034223b6fc68ed97deb4cf59bc1d0d19b2cd345b2dbe660a3acfaaca708

Contents?: true

Size: 1.15 KB

Versions: 7

Compression:

Stored size: 1.15 KB

Contents

module Saucy
  module Account
    extend ActiveSupport::Concern

    included do
      has_many :memberships, :dependent => :destroy
      has_many :users, :through => :memberships
      has_many :projects, :dependent => :destroy
      has_many :admins, :through    => :memberships,
                        :source     => :user,
                        :conditions => { 'memberships.admin' => true }

      belongs_to :plan

      validates_uniqueness_of :name, :keyword
      validates_presence_of :name, :keyword

      attr_accessible :name, :keyword

      validates_format_of :keyword,
                          :with    => %r{^[a-z0-9]+$},
                          :message => "must be only lower case letters."
    end

    module InstanceMethods
      def to_param
        keyword
      end

      def has_member?(user)
        memberships.exists?(:user_id => user.id)
      end

      def users_by_name
        users.by_name
      end

      def projects_by_name
        projects.by_name
      end

      def projects_visible_to(user)
        projects.visible_to(user)
      end

      def memberships_by_name
        memberships.by_name
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
saucy-0.1.18 lib/saucy/account.rb
saucy-0.1.17 lib/saucy/account.rb
saucy-0.1.16 lib/saucy/account.rb
saucy-0.1.15 lib/saucy/account.rb
saucy-0.1.14 lib/saucy/account.rb
saucy-0.1.13 lib/saucy/account.rb
saucy-0.1.12 lib/saucy/account.rb