Skip to content

Commit

Permalink
Merge pull request #44 from thatch-health/auditor-name-method
Browse files Browse the repository at this point in the history
Add configuration option for auditor method name attribute
  • Loading branch information
jorgemanrubia committed Jun 15, 2023
2 parents ec59bd6 + c4b3cf4 commit b2a5c3d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ These config options are namespaced in `config.audits1984`:
| Name | Description |
| --------------------- | ------------------------------------------------------------ |
| auditor_class | The name of the auditor class. By default it's `::User.` |
| auditor_name_attribute | The attribute on the auditor class that returns the auditor's name. By default it's `:name`. |
| base_controller_class | The host application base class that will be the parent of `audit1984` controllers. By default it's `::ApplicationController`. |

8 changes: 8 additions & 0 deletions app/helpers/audits1984/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

module Audits1984
module ApplicationHelper
def get_auditor_name(auditor)
if auditor == Audits1984::Current.auditor
"You"
else
auditor.public_send(Audits1984.auditor_name_attribute)
end
end

def format_date(date)
# <time datetime="2016-1-1">11:09 PM - 1 Jan 2016</time>
date.strftime("%Y-%m-%d")
Expand Down
2 changes: 1 addition & 1 deletion app/views/audits1984/sessions/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ul class="mb-6">
<% session.audits.except(&:new_record?).each do |audit| %>
<li> <%= audit.status.humanize %>
by <%= audit.auditor == Audits1984::Current.auditor ? "You" : audit.auditor.name %>
by <%= get_auditor_name(audit.auditor) %>
on <%= format_date_and_time(audit.created_at) %>
</li>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions lib/audits1984.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@

module Audits1984
mattr_accessor :auditor_class, default: "::User"
mattr_accessor :auditor_name_attribute, default: :name
mattr_accessor :base_controller_class, default: "::ApplicationController"
end

0 comments on commit b2a5c3d

Please sign in to comment.