Module: ProxES::Helpers::Pundit
Instance Method Summary collapse
- #authorize(record, query = nil) ⇒ Object
- #permitted_attributes(record, action) ⇒ Object
- #pundit_user ⇒ Object
Instance Method Details
#authorize(record, query = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/proxes/helpers/pundit.rb', line 10 def (record, query = nil) if record.is_a?(Request) query = record.request_method.downcase elsif query.nil? raise ArgumentError, 'Pundit cannot determine the query' end query = :"#{query}?" unless query[-1] == '?' super end |
#permitted_attributes(record, action) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/proxes/helpers/pundit.rb', line 20 def permitted_attributes(record, action) param_key = PolicyFinder.new(record).param_key policy = policy(record) method_name = if policy.respond_to?("permitted_attributes_for_#{action}") "permitted_attributes_for_#{action}" else 'permitted_attributes' end request.params.fetch(param_key, {}).select do |key, _value| policy.public_send(method_name).include? key.to_sym end end |
#pundit_user ⇒ Object
34 35 36 |
# File 'lib/proxes/helpers/pundit.rb', line 34 def pundit_user current_user end |