Class: Portier::Base
- Inherits:
-
Object
- Object
- Portier::Base
- Defined in:
- lib/portier/base.rb
Overview
************************************************************************************* Check if the access is granted or refused depending on the permission setted in the permission files. *************************************************************************************
Instance Attribute Summary collapse
-
#application_controller ⇒ Object
readonly
Returns the value of attribute application_controller.
-
#current_user ⇒ Object
readonly
Returns the value of attribute current_user.
Instance Method Summary collapse
- #access_denied_message ⇒ Object
- #authorize_action ⇒ Object
- #can?(action, object, options = {}) ⇒ Boolean
- #can_view?(tag, options = {}) ⇒ Boolean
-
#initialize(application_controller, current_user) ⇒ Base
constructor
A new instance of Base.
- #permitted_params ⇒ Object
Constructor Details
#initialize(application_controller, current_user) ⇒ Base
Returns a new instance of Base.
10 11 12 13 |
# File 'lib/portier/base.rb', line 10 def initialize(application_controller, current_user) @application_controller = application_controller @current_user = current_user end |
Instance Attribute Details
#application_controller ⇒ Object (readonly)
Returns the value of attribute application_controller.
6 7 8 |
# File 'lib/portier/base.rb', line 6 def application_controller @application_controller end |
#current_user ⇒ Object (readonly)
Returns the value of attribute current_user.
6 7 8 |
# File 'lib/portier/base.rb', line 6 def current_user @current_user end |
Instance Method Details
#access_denied_message ⇒ Object
15 16 17 |
# File 'lib/portier/base.rb', line 15 def . end |
#authorize_action ⇒ Object
19 20 21 |
# File 'lib/portier/base.rb', line 19 def raise Portier::AccessDenied if not .granted? action end |
#can?(action, object, options = {}) ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/portier/base.rb', line 23 def can?(action, object, ={}) object_name = if object.is_a? Symbol or object.is_a? String object.to_s.singularize.pluralize else object.class.name.pluralize end object_name = "#{[:namespace].to_s.camelize}::#{object_name.camelize}" if [:namespace] = object_name .can? action, object, end |
#can_view?(tag, options = {}) ⇒ Boolean
36 37 38 |
# File 'lib/portier/base.rb', line 36 def can_view?(tag, ={}) .can_view? tag, end |
#permitted_params ⇒ Object
40 41 42 |
# File 'lib/portier/base.rb', line 40 def permitted_params .build_permitted_params if .respond_to? :permitted_params end |