Class: Plutonium::Resource::Policy
- Inherits:
-
ActionPolicy::Base
- Object
- ActionPolicy::Base
- Plutonium::Resource::Policy
- Defined in:
- lib/plutonium/resource/policy.rb
Overview
Policy class to define permissions and attributes for a resource. This class provides methods to check permissions for various actions and to retrieve permitted attributes for these actions.
Instance Method Summary collapse
-
#create? ⇒ Boolean
Checks if the create action is permitted.
-
#destroy? ⇒ Boolean
Checks if the destroy action is permitted.
-
#edit? ⇒ Boolean
Checks if the edit action is permitted.
-
#index? ⇒ Boolean
Checks if the index action is permitted.
-
#new? ⇒ Boolean
Checks if the new action is permitted.
-
#permitted_associations ⇒ Array<Symbol>
Returns the permitted associations.
-
#permitted_attributes_for_create ⇒ Array<Symbol>
Returns the permitted attributes for the create action.
-
#permitted_attributes_for_edit ⇒ Array<Symbol>
Returns the permitted attributes for the edit action.
-
#permitted_attributes_for_index ⇒ Array<Symbol>
Returns the permitted attributes for the index action.
-
#permitted_attributes_for_new ⇒ Array<Symbol>
Returns the permitted attributes for the new action.
-
#permitted_attributes_for_read ⇒ Array<Symbol>
Returns the permitted attributes for the read action.
-
#permitted_attributes_for_show ⇒ Array<Symbol>
Returns the permitted attributes for the show action.
-
#permitted_attributes_for_update ⇒ Array<Symbol>
Returns the permitted attributes for the update action.
-
#read? ⇒ Boolean
Checks if the read action is permitted.
-
#search? ⇒ Boolean
Checks if record search is permitted.
-
#send_with_report(method) ⇒ Object
Sends a method and raises an error if the method is not implemented.
-
#show? ⇒ Boolean
Checks if the show action is permitted.
-
#update? ⇒ Boolean
Checks if the update action is permitted.
Instance Method Details
#create? ⇒ Boolean
Checks if the create action is permitted.
34 35 36 |
# File 'lib/plutonium/resource/policy.rb', line 34 def create? false end |
#destroy? ⇒ Boolean
Checks if the destroy action is permitted.
55 56 57 |
# File 'lib/plutonium/resource/policy.rb', line 55 def destroy? create? end |
#edit? ⇒ Boolean
Checks if the edit action is permitted.
85 86 87 |
# File 'lib/plutonium/resource/policy.rb', line 85 def edit? update? end |
#index? ⇒ Boolean
Checks if the index action is permitted.
64 65 66 |
# File 'lib/plutonium/resource/policy.rb', line 64 def index? read? end |
#new? ⇒ Boolean
Checks if the new action is permitted.
71 72 73 |
# File 'lib/plutonium/resource/policy.rb', line 71 def new? create? end |
#permitted_associations ⇒ Array<Symbol>
Returns the permitted associations.
155 156 157 |
# File 'lib/plutonium/resource/policy.rb', line 155 def permitted_associations [] end |
#permitted_attributes_for_create ⇒ Array<Symbol>
Returns the permitted attributes for the create action.
101 102 103 104 105 106 |
# File 'lib/plutonium/resource/policy.rb', line 101 def permitted_attributes_for_create autodetect_permitted_fields(:permitted_attributes_for_create) - [ resource_class.primary_key.to_sym, # primary_key :created_at, :updated_at # timestamps ] end |
#permitted_attributes_for_edit ⇒ Array<Symbol>
Returns the permitted attributes for the edit action.
148 149 150 |
# File 'lib/plutonium/resource/policy.rb', line 148 def permitted_attributes_for_edit permitted_attributes_for_update end |
#permitted_attributes_for_index ⇒ Array<Symbol>
Returns the permitted attributes for the index action.
127 128 129 |
# File 'lib/plutonium/resource/policy.rb', line 127 def permitted_attributes_for_index permitted_attributes_for_read end |
#permitted_attributes_for_new ⇒ Array<Symbol>
Returns the permitted attributes for the new action.
141 142 143 |
# File 'lib/plutonium/resource/policy.rb', line 141 def permitted_attributes_for_new permitted_attributes_for_create end |
#permitted_attributes_for_read ⇒ Array<Symbol>
Returns the permitted attributes for the read action.
111 112 113 |
# File 'lib/plutonium/resource/policy.rb', line 111 def permitted_attributes_for_read autodetect_permitted_fields(:permitted_attributes_for_read) end |
#permitted_attributes_for_show ⇒ Array<Symbol>
Returns the permitted attributes for the show action.
134 135 136 |
# File 'lib/plutonium/resource/policy.rb', line 134 def permitted_attributes_for_show permitted_attributes_for_read end |
#permitted_attributes_for_update ⇒ Array<Symbol>
Returns the permitted attributes for the update action.
118 119 120 |
# File 'lib/plutonium/resource/policy.rb', line 118 def permitted_attributes_for_update permitted_attributes_for_create end |
#read? ⇒ Boolean
Checks if the read action is permitted.
41 42 43 |
# File 'lib/plutonium/resource/policy.rb', line 41 def read? false end |
#search? ⇒ Boolean
Checks if record search is permitted.
92 93 94 |
# File 'lib/plutonium/resource/policy.rb', line 92 def search? index? end |
#send_with_report(method) ⇒ Object
Sends a method and raises an error if the method is not implemented.
21 22 23 24 25 26 27 |
# File 'lib/plutonium/resource/policy.rb', line 21 def send_with_report(method) unless respond_to?(method) raise NotImplementedError, "#{self.class.name} does not implement the required #{method}" end public_send(method) end |
#show? ⇒ Boolean
Checks if the show action is permitted.
78 79 80 |
# File 'lib/plutonium/resource/policy.rb', line 78 def show? read? end |
#update? ⇒ Boolean
Checks if the update action is permitted.
48 49 50 |
# File 'lib/plutonium/resource/policy.rb', line 48 def update? create? end |