Module: Canner
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/canner.rb,
lib/canner/policy.rb,
lib/canner/version.rb,
lib/generators/canner/policy/policy_generator.rb,
lib/generators/canner/fetch_roles/fetch_roles_generator.rb
Defined Under Namespace
Modules: Generators Classes: AuthNotUsedError, NotAuthorizedError, Policy, ScopeNotUsedError
Constant Summary collapse
- VERSION =
"0.2.0"
Instance Method Summary collapse
- #auth_used ⇒ Object
-
#can?(method_name, target_model) ⇒ Boolean
method_name - The controller action method that you are concerned with access target_model - Name of the object you are limiting access to.
-
#canner_branch ⇒ Object
override this if your method for getting the current branch isn’t called current_branch.
-
#canner_scope(method_name, target_model) ⇒ Object
method_name - The controller action method that you are concerned with access target_model - Name of the object you are limiting access to.
-
#canner_user ⇒ Object
override this if your method for getting the current user isn’t called current_user.
-
#instance_can?(method_name, target_model, target_obj) ⇒ Boolean
method_name - The controller action method that you are concerned with access target_model - Name of the object you are limiting access to.
- #scope_used ⇒ Object
Instance Method Details
#auth_used ⇒ Object
26 27 28 |
# File 'lib/canner.rb', line 26 def auth_used @auth_used ||= false end |
#can?(method_name, target_model) ⇒ Boolean
method_name - The controller action method that you are concerned with access target_model - Name of the object you are limiting access to. ( :user, :pet, :customer )
45 46 47 48 49 |
# File 'lib/canner.rb', line 45 def can?(method_name, target_model) @auth_used = true raise NotAuthorizedError.new("You are not authorized to perform this action.") unless canner_policy(method_name, target_model).can? true end |
#canner_branch ⇒ Object
override this if your method for getting the current branch isn’t called current_branch.
64 65 66 |
# File 'lib/canner.rb', line 64 def canner_branch current_branch rescue nil end |
#canner_scope(method_name, target_model) ⇒ Object
method_name - The controller action method that you are concerned with access target_model - Name of the object you are limiting access to. ( :user, :pet, :customer )
53 54 55 56 |
# File 'lib/canner.rb', line 53 def canner_scope(method_name, target_model) @scope_used = true canner_policy(method_name, target_model).canner_scope end |
#canner_user ⇒ Object
override this if your method for getting the current user isn’t called current_user.
59 60 61 |
# File 'lib/canner.rb', line 59 def canner_user current_user end |
#instance_can?(method_name, target_model, target_obj) ⇒ Boolean
method_name - The controller action method that you are concerned with access target_model - Name of the object you are limiting access to. ( :user, :pet, :customer ) target_obj - The instance obj for what you want to test. ( does user 1 have access to company 1?)
37 38 39 40 41 |
# File 'lib/canner.rb', line 37 def instance_can?(method_name, target_model, target_obj) policy = canner_policy(method_name, target_model) raise NotAuthorizedError.new("You do not have access to this #{target_model.capitalize}") unless policy.instance_can?(target_obj) true end |
#scope_used ⇒ Object
30 31 32 |
# File 'lib/canner.rb', line 30 def scope_used @scope_used ||= false end |