Sha256: b043a6efe03a8ddc5bbb16fa529f835b8775a2a3c369dcbc79d5dc78759a99bc

Contents?: true

Size: 670 Bytes

Versions: 3

Compression:

Stored size: 670 Bytes

Contents

module Formol    
  module Permissions
    class Manager
      attr_accessor :user
      cattr_accessor :profiles
      
      def initialize(user)
        self.user = user
        @profile_name = (user && user.persisted? ? user.formol_profile : :default).to_sym
      end
      
      def able_to?(right, obj = nil)
        return true if has_right?(:administrate)
        
        respond_to?(m = :"able_to_#{right}?") ? send(m, obj) : has_right?(right)
      end
      
      protected
      
      def profile
        self.class.profiles[@profile_name]
      end
      
      def has_right?(right)
        profile.has_right?(right.to_sym)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formol-0.0.6 lib/formol/permissions/manager.rb
formol-0.0.5 lib/formol/permissions/manager.rb
formol-0.0.4 lib/formol/permissions/manager.rb