Class: BasePolicy
- Inherits:
-
Object
- Object
- BasePolicy
- Defined in:
- lib/generators/canner/install/templates/base_policy.rb
Instance Method Summary collapse
-
#can? ⇒ Boolean
implment in your policy class.
-
#canner_scope ⇒ Object
implement in your policy class to auto scope in an action.
-
#fetch_roles ⇒ Object
implement this in your policy class expects an array or strings or symbols that represent the user roles.
-
#initialize(current_user, current_branch, method) ⇒ BasePolicy
constructor
A new instance of BasePolicy.
Constructor Details
#initialize(current_user, current_branch, method) ⇒ BasePolicy
3 4 5 6 7 8 |
# File 'lib/generators/canner/install/templates/base_policy.rb', line 3 def initialize(current_user, current_branch, method) @current_user = current_user @current_branch = current_branch @method = method.to_sym @roles = fetch_roles end |
Instance Method Details
#can? ⇒ Boolean
implment in your policy class. return true when the user can access the action or resource and false when they can’t
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/generators/canner/install/templates/base_policy.rb', line 31 def can? raise ArgumentError.new("NOT IMPLEMENTED") # ex: # case @method # when :index, :show # has_role?(:admin) # else # false # end end |
#canner_scope ⇒ Object
implement in your policy class to auto scope in an action
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/generators/canner/install/templates/base_policy.rb', line 18 def canner_scope raise ArgumentError.new("NOT IMPLEMENTED") # ex: # case @method # when :index # User.by_branch(@current_branch) # else # User.none # end end |
#fetch_roles ⇒ Object
implement this in your policy class expects an array or strings or symbols that represent the user roles
12 13 14 15 |
# File 'lib/generators/canner/install/templates/base_policy.rb', line 12 def fetch_roles raise ArgumentError.new("YOU NEED TO IMPLEMENT") # ex. User.roles end |