Module: Subroutine::Auth::ClassMethods

Defined in:
lib/subroutine/auth.rb

Instance Method Summary collapse

Instance Method Details

#authorize(validation_name) ⇒ Object



30
31
32
# File 'lib/subroutine/auth.rb', line 30

def authorize(validation_name)
  validate validation_name, unless: :skip_auth_checks?
end

#no_user_requirements!Object



34
35
36
# File 'lib/subroutine/auth.rb', line 34

def no_user_requirements!
  self.authorization_declared = true
end

#policy(*meths) ⇒ Object

policy :can_update_user policy :can_do_whatever, policy: :foo_policy



56
57
58
59
60
61
62
63
64
65
# File 'lib/subroutine/auth.rb', line 56

def policy(*meths)
  opts = meths.extract_options!
  policy_name = opts[:policy] || :policy
  validate unless: :skip_auth_checks? do
    p = self.send(policy_name)
    if !p || meths.any?{|m| !(p.respond_to?("#{m}?") ? p.send("#{m}?") : p.send(m)) }
      unauthorized! opts[:error]
    end
  end
end

#require_no_user!Object



46
47
48
49
50
51
52
# File 'lib/subroutine/auth.rb', line 46

def require_no_user!
  self.authorization_declared = true

  validate unless: :skip_auth_checks? do
    unauthorized! :empty_unauthorized if current_user.present?
  end
end

#require_user!Object



38
39
40
41
42
43
44
# File 'lib/subroutine/auth.rb', line 38

def require_user!
  self.authorization_declared = true

  validate unless: :skip_auth_checks? do
    unauthorized! unless current_user.present?
  end
end