Module: Challah::Rolls::User

Defined in:
lib/challah/rolls/user.rb

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Instance Method Summary collapse

Instance Method Details

#challah_rolls_userObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/challah/rolls/user.rb', line 4

def challah_rolls_user
  unless included_modules.include?(InstanceMethods)
    include InstanceMethods
    extend ClassMethods
  end

  class_eval do
    validates :role_id,         :presence => true

    # Relationships
    ################################################################

    belongs_to :role,             :touch => true

    has_many :permission_users,   :dependent => :destroy

    has_many :permissions,        :through => :permission_users,
                                  :order => 'permissions.name'

    # Scoped Finders
    ################################################################

    scope :with_role,   lambda { |role| where([ "users.role_id = ?", role ]) }

    # Callbacks
    ################################################################

    after_save          :save_permission_keys
  end
end