Module: Subroutine::Auth::ClassMethods
- Defined in:
- lib/subroutine/auth.rb
Instance Method Summary collapse
- #authorize(validation_name) ⇒ Object
- #no_user_requirements! ⇒ Object
-
#policy(*meths) ⇒ Object
policy :can_update_user policy :can_do_whatever, policy: :foo_policy.
- #require_no_user! ⇒ Object
- #require_user! ⇒ Object
Instance Method Details
#authorize(validation_name) ⇒ Object
30 31 32 |
# File 'lib/subroutine/auth.rb', line 30 def (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. = 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. 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)) } 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. = true validate unless: :skip_auth_checks? do :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. = true validate unless: :skip_auth_checks? do unless current_user.present? end end |