Class: AuditLog

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/audit_log.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

allow items to be looked up by method calls



29
30
31
32
33
34
35
36
# File 'app/models/audit_log.rb', line 29

def method_missing(m, *args, &block)
  if self.respond_to?(m)
    item = get_item_by_item_type_internal_identifier(m.to_s)
    (item.nil?) ? super : (return item.audit_log_item_value)
  else
    super
  end
end

Class Method Details

.custom_application_log_message(party, msg) ⇒ Object



39
40
41
42
43
44
45
# File 'app/models/audit_log.rb', line 39

def custom_application_log_message(party, msg)
  self.create(
    :party_id => party.id,
    :audit_log_type => AuditLogType.find_by_type_and_subtype_iid('application','custom_message'),
    :description => "#{party.description}: #{msg}"
  )
end

.party_access(party, url) ⇒ Object



63
64
65
66
67
68
69
# File 'app/models/audit_log.rb', line 63

def party_access(party, url)
  self.create(
    :party_id => party.id,
    :audit_log_type => AuditLogType.find_by_type_and_subtype_iid('application','accessed_area'),
    :description => "#{party.description} has accessed area #{url}"
  )
end

.party_failed_access(party, url) ⇒ Object



71
72
73
74
75
76
77
# File 'app/models/audit_log.rb', line 71

def party_failed_access(party, url)
  self.create(
    :party_id => party.id,
    :audit_log_type => AuditLogType.find_by_type_and_subtype_iid('application','accessed_area'),
    :description => "#{party.description} has tried to access a restricted area #{url}"
  )
end

.party_login(party) ⇒ Object



55
56
57
58
59
60
61
# File 'app/models/audit_log.rb', line 55

def (party)
  self.create(
    :party_id => party.id,
    :audit_log_type => AuditLogType.find_by_type_and_subtype_iid('application','successful_login'),
    :description => "#{party.description} has logged in"
  )
end

.party_logout(party) ⇒ Object



47
48
49
50
51
52
53
# File 'app/models/audit_log.rb', line 47

def party_logout(party)
  self.create(
    :party_id => party.id,
    :audit_log_type => AuditLogType.find_by_type_and_subtype_iid('application','successful_logout'),
    :description => "#{party.description} has logged out"
  )
end

.party_session_timeout(party) ⇒ Object



79
80
81
82
83
84
85
# File 'app/models/audit_log.rb', line 79

def party_session_timeout(party)
  self.create(
    :party_id => party.id,
    :audit_log_type => AuditLogType.find_by_type_and_subtype_iid('application','session_timeout'),
    :description => "#{party.description} session has expired"
  )
end

Instance Method Details

#get_item_by_item_type_internal_identifier(item_type_internal_identifier) ⇒ Object



18
19
20
21
# File 'app/models/audit_log.rb', line 18

def get_item_by_item_type_internal_identifier(item_type_internal_identifier)
  self.items.includes(:audit_log_item_type)
            .where(:audit_log_item_types => {:internal_identifier => item_type_internal_identifier}).first
end

#respond_to?(m, include_private_methods = false) ⇒ Boolean

allow items to be looked up by method calls

Returns:

  • (Boolean)


24
25
26
# File 'app/models/audit_log.rb', line 24

def respond_to?(m, include_private_methods = false)
  (super ? true : get_item_by_item_type_internal_identifier(m.to_s)) rescue super
end