Module: Ixtlan::Models::Audit

Defined in:
lib/ixtlan/models/audit.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(model) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ixtlan/models/audit.rb', line 5

def self.included(model)
  model.send(:include, DataMapper::Resource)

  model.property :id, ::DataMapper::Types::Serial

  model.property :date, DateTime, :required => true

  model.property :login, String, :required => true, :format => /^[a-zA-Z0-9]+$/, :length => 32, :auto_validation => false #required => true does not allow empty string :-( so skip validation

  model.property :message, String, :required => true, :length => 255

  model.class_eval "unless const_defined? \"CONFIGURATION\"\n  CONFIGURATION = Object.full_const_get(Models::CONFIGURATION)\nend\ndef self.pop_all\n  result = Thread.current[:audit] || []\n  Thread.current[:audit] = nil\n  if(!@last_cleanup.nil? && @last_cleanup < 1.days.ago)\n    @last_cleanup = Date.today\n    begin\n      self.class.all(:date.lt => CONFIGURATION.keep_audit_log.days.ago).destroy!\n    rescue Error\n      # TODO log this !!\n    end\n  end\n  result\nend\n", __FILE__, __LINE__
end

Instance Method Details

#pushObject



36
37
38
39
# File 'lib/ixtlan/models/audit.rb', line 36

def push
  list = (Thread.current[:audit] ||= [])
  list << self
end