Class: RsUserPolicy::AuditLog
- Inherits:
-
Object
- Object
- RsUserPolicy::AuditLog
- Defined in:
- lib/rs_user_policy/audit_log.rb
Instance Attribute Summary collapse
-
#audit_log ⇒ Object
Returns the value of attribute audit_log.
-
#filename ⇒ Object
Returns the value of attribute filename.
Instance Method Summary collapse
-
#add_entry(email, account, action, changes) ⇒ Object
Adds a new entry to the audit log.
-
#initialize(options = {}) ⇒ AuditLog
constructor
Initializes a new AuditLog.
-
#write_file ⇒ Object
Writes the audit log to a file.
Constructor Details
#initialize(options = {}) ⇒ AuditLog
Initializes a new AuditLog
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rs_user_policy/audit_log.rb', line 33 def initialize(={}) = [:timestamp] || Time.now.to_i @audit_log = {} @filename = '' if [:audit_dir] @filename << ::File.join([:audit_dir], 'audit_log') else @filename << 'audit_log' end if [:dry_run] @filename << '_dryrun' end @filename << "-#{}.json" end |
Instance Attribute Details
#audit_log ⇒ Object
Returns the value of attribute audit_log.
25 26 27 |
# File 'lib/rs_user_policy/audit_log.rb', line 25 def audit_log @audit_log end |
#filename ⇒ Object
Returns the value of attribute filename.
25 26 27 |
# File 'lib/rs_user_policy/audit_log.rb', line 25 def filename @filename end |
Instance Method Details
#add_entry(email, account, action, changes) ⇒ Object
Adds a new entry to the audit log
57 58 59 60 61 62 63 64 |
# File 'lib/rs_user_policy/audit_log.rb', line 57 def add_entry(email, account, action, changes) @audit_log[email] = [] unless audit_log[email] @audit_log[email] << { :account => account, :action => action, :changes => changes } end |
#write_file ⇒ Object
Writes the audit log to a file
68 69 70 |
# File 'lib/rs_user_policy/audit_log.rb', line 68 def write_file File.open(@filename, 'w') {|f| f.write(JSON.pretty_generate(@audit_log))} end |