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
11 12 13 14 15 16 17 18 19 |
# File 'lib/proxes/helpers/pundit.rb', line 11 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
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/proxes/helpers/pundit.rb', line 21 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
35 36 37 |
# File 'lib/proxes/helpers/pundit.rb', line 35 def pundit_user current_user end |