Module: Adeia::ControllerMethods
- Defined in:
- lib/adeia/controller_methods.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #authorize!(**args) ⇒ Object
- #authorize_and_load_records!(**args) ⇒ Object
- #can?(action, element, resource = nil) ⇒ Boolean
- #load_and_authorize!(**args) ⇒ Object
- #load_records(**args) ⇒ Object
-
#redirect_back_or(default, **args) ⇒ Object
Redirect the user to the stored url or the default one provided.
- #require_login! ⇒ Object
- #rights?(action, element, resource = nil) ⇒ Boolean
-
#store_location ⇒ Object
Store the current url in a cookie.
Class Method Details
.included(base) ⇒ Object
20 21 22 23 |
# File 'lib/adeia/controller_methods.rb', line 20 def self.included(base) base.extend ClassMethods base.helper_method :can?, :rights? end |
Instance Method Details
#authorize!(**args) ⇒ Object
43 44 45 |
# File 'lib/adeia/controller_methods.rb', line 43 def (**args) ControllerResource.new(self, **args). end |
#authorize_and_load_records!(**args) ⇒ Object
32 33 34 35 36 |
# File 'lib/adeia/controller_methods.rb', line 32 def (**args) controller_resource = ControllerResource.new(self, **args) controller_resource. return controller_resource.load_records end |
#can?(action, element, resource = nil) ⇒ Boolean
54 55 56 |
# File 'lib/adeia/controller_methods.rb', line 54 def can?(action, element, resource=nil) ControllerResource.new(self, action: action).(:can?, element, resource) end |
#load_and_authorize!(**args) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/adeia/controller_methods.rb', line 25 def (**args) controller_resource = ControllerResource.new(self, **args) resource = controller_resource.load_resource controller_resource. return resource end |
#load_records(**args) ⇒ Object
38 39 40 41 |
# File 'lib/adeia/controller_methods.rb', line 38 def load_records(**args) controller_resource = ControllerResource.new(self, **args) return controller_resource.load_records end |
#redirect_back_or(default, **args) ⇒ Object
Redirect the user to the stored url or the default one provided
-
Args :
-
default path to redirect to
-
-
Returns :
68 69 70 71 |
# File 'lib/adeia/controller_methods.rb', line 68 def redirect_back_or(default, **args) redirect_to([:return_to] || default, **args) .delete(:return_to) end |
#require_login! ⇒ Object
47 48 49 50 51 52 |
# File 'lib/adeia/controller_methods.rb', line 47 def require_login! unless signed_in? store_location raise LoginRequired end end |
#rights?(action, element, resource = nil) ⇒ Boolean
58 59 60 |
# File 'lib/adeia/controller_methods.rb', line 58 def rights?(action, element, resource=nil) ControllerResource.new(self, action: action).(:rights?, element, resource) end |
#store_location ⇒ Object
Store the current url in a cookie
-
Args :
-
Returns :
79 80 81 |
# File 'lib/adeia/controller_methods.rb', line 79 def store_location [:return_to] = request.fullpath if request.get? end |