Sha256: 99ddd6f3a0eaf0e78ebf7700366b5b36cb70f47772d63eb3d6564903ba0b9977

Contents?: true

Size: 692 Bytes

Versions: 8

Compression:

Stored size: 692 Bytes

Contents

module Credentials
  module Extensions
    # Allows you to use magic methods to test permissions.
    # For example:
    #
    #     class User
    #       credentials do |user|
    #         user.can :edit, :self
    #       end
    #     end
    #     
    #     user = User.new
    #     user.can_edit? user #=> true
    module MagicMethods
      def self.included(receiver) #:nodoc:
        receiver.class_eval do
          def method_missing(sym, *args)
            if self.class != Object && self.class != Class && sym.to_s =~ /\Acan_(.*)\?\z/
              can? $1.to_sym, *args
            else
              super
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
credentials-2.4.3 lib/credentials/extensions/magic_methods.rb
credentials-2.4.2 lib/credentials/extensions/magic_methods.rb
credentials-2.4.1 lib/credentials/extensions/magic_methods.rb
credentials-2.4.0 lib/credentials/extensions/magic_methods.rb
credentials-2.3.1 lib/credentials/extensions/magic_methods.rb
credentials-2.3.0 lib/credentials/extensions/magic_methods.rb
credentials-2.2.3 lib/credentials/extensions/magic_methods.rb
credentials-2.2.2 lib/credentials/extensions/magic_methods.rb