active-audit 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_audit/audit.rb +8 -7
- data/lib/active_audit/audit_repository.rb +1 -1
- data/lib/active_audit/base.rb +1 -1
- data/lib/active_audit/sweeper.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1319b7111b54ac97687b736ad1101c522f69dfd4
|
4
|
+
data.tar.gz: 69b1ff6a16208158898598b169c621ee82ef5138
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76d46d974a83c641a6c3892bbceab7523b11c3627a6af24f7db71c404a1064138048238dddf5b525187c3c33668c4a14b50d3fe5c74a43c153083284f66b00f9
|
7
|
+
data.tar.gz: 666fc0d4d1259e2556ae74e045b1bb5875b35683550eaab8639efbd43e3a54f855ff676800e599ef3f7930be1a84128b07bf8595bc71aaa18912d47d85609ac8
|
data/lib/active_audit/audit.rb
CHANGED
@@ -8,6 +8,7 @@ module ActiveAudit
|
|
8
8
|
|
9
9
|
extend ActiveModel::Callbacks
|
10
10
|
define_model_callbacks :create, :save
|
11
|
+
define_model_callbacks :initialize, :only => :after
|
11
12
|
|
12
13
|
include ActiveModel::Observing
|
13
14
|
|
@@ -19,16 +20,12 @@ module ActiveAudit
|
|
19
20
|
attribute :comment, String
|
20
21
|
attribute :recorded_at, Time, default: lambda { |o,a| Time.now.utc }
|
21
22
|
|
22
|
-
before_save do
|
23
|
-
self.recorded_at = Time.at(self.recorded_at) if self.recorded_at.is_a? Integer
|
24
|
-
self.attributed_to = ActiveAudit.extract_user_profile.call(self.attributed_to) unless self.attributed_to.nil? || self.attributed_to.is_a?(Hash)
|
25
|
-
end
|
26
|
-
|
27
23
|
def initialize *args
|
28
24
|
attributes = args.extract_options!
|
29
25
|
if attributes.empty?
|
30
26
|
if args.count == 2
|
31
27
|
initialize_from_record(*args)
|
28
|
+
run_callbacks :initialize
|
32
29
|
else
|
33
30
|
raise ArgumentError, "You need to supply at least one attribute"
|
34
31
|
end
|
@@ -76,8 +73,12 @@ module ActiveAudit
|
|
76
73
|
object
|
77
74
|
end
|
78
75
|
|
79
|
-
def serialize
|
80
|
-
|
76
|
+
def self.serialize audit
|
77
|
+
audit.attributes.select {|k,v| v.present?}.merge(recorded_at: audit.recorded_at.to_i)
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.deserialize attributes
|
81
|
+
self.new attributes.update(recorded_at: Time.at(attributes[:recorded_at]))
|
81
82
|
end
|
82
83
|
end
|
83
84
|
end
|
data/lib/active_audit/base.rb
CHANGED
data/lib/active_audit/sweeper.rb
CHANGED
@@ -16,8 +16,8 @@ module ActiveAudit
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
audit.attributed_to = self.user if self.user
|
19
|
+
def after_initialize audit
|
20
|
+
audit.attributed_to = ActiveAudit.extract_user_profile.call(self.user) if self.user
|
21
21
|
audit.comment = controller.params[:comment] if controller.respond_to?(:params, true)
|
22
22
|
audit.comment ||= ActiveAudit.session[:comment]
|
23
23
|
end
|