Module: Subroutine::Auth

Defined in:
lib/subroutine/auth.rb

Defined Under Namespace

Modules: ClassMethods Classes: NotAuthorizedError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/subroutine/auth.rb', line 18

def self.included(base)
  base.instance_eval do
    extend ::Subroutine::Auth::ClassMethods

    class_attribute :authorization_declared
    self.authorization_declared = false
  end
end

Instance Method Details

#current_userObject



86
87
88
89
# File 'lib/subroutine/auth.rb', line 86

def current_user
  @current_user = ::User.find(@current_user) if Fixnum === @current_user
  @current_user
end

#initialize(*args) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/subroutine/auth.rb', line 69

def initialize(*args)
  raise "Authorization management has not been declared on this class" if(!self.class.authorization_declared)

  super(args.extract_options!)
  @skip_auth_checks = false
  @current_user = args.shift
end

#skip_auth_checks!Object



77
78
79
80
# File 'lib/subroutine/auth.rb', line 77

def skip_auth_checks!
  @skip_auth_checks = true
  self
end

#skip_auth_checks?Boolean



82
83
84
# File 'lib/subroutine/auth.rb', line 82

def skip_auth_checks?
  !!@skip_auth_checks
end

#unauthorized!(reason = nil) ⇒ Object



91
92
93
94
# File 'lib/subroutine/auth.rb', line 91

def unauthorized!(reason = nil)
  reason ||= :unauthorized
  raise ::Subroutine::Auth::NotAuthorizedError.new(reason)
end