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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 415a536bf1baa3b6406ab790ceb32011b4b4bf93
4
- data.tar.gz: 6053cc7939434e6ab197634f0f0b60c499ee2b7a
3
+ metadata.gz: 1319b7111b54ac97687b736ad1101c522f69dfd4
4
+ data.tar.gz: 69b1ff6a16208158898598b169c621ee82ef5138
5
5
  SHA512:
6
- metadata.gz: 5ac94740df196d66b91db31f820b7a796a4abd3a076149501474c5b2e26de18a26361fcf0dcfd44b58f15376babe909fee82d51a998014688b9b5b782d68391f
7
- data.tar.gz: af5f84180dd9f6d9cd582aab0b1b00b345b39e0fce75f1b6d344d74039f532c571f90f08a889a4c9a4f7fb97eb0a214cbb90e95d25560b5d23691e44ec2a97b7
6
+ metadata.gz: 76d46d974a83c641a6c3892bbceab7523b11c3627a6af24f7db71c404a1064138048238dddf5b525187c3c33668c4a14b50d3fe5c74a43c153083284f66b00f9
7
+ data.tar.gz: 666fc0d4d1259e2556ae74e045b1bb5875b35683550eaab8639efbd43e3a54f855ff676800e599ef3f7930be1a84128b07bf8595bc71aaa18912d47d85609ac8
@@ -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
- self.attributes.select {|k,v| v.present?}.merge(recorded_at: self.recorded_at.to_i, type: self.type)
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
@@ -14,7 +14,7 @@ module ActiveAudit
14
14
  end
15
15
 
16
16
  def create attributes
17
- save Audit.new(attributes)
17
+ save Audit.deserialize(attributes)
18
18
  end
19
19
 
20
20
  def save audit
@@ -70,7 +70,7 @@ module ActiveAudit
70
70
  audit = Audit.new event, self
71
71
  if audit.changed?
72
72
  if ActiveAudit.delayed_auditing
73
- AuditPusher.perform_later audit.serialize
73
+ AuditPusher.perform_later Audit.serialize(audit)
74
74
  else
75
75
  AuditRepository.save(audit)
76
76
  end
@@ -16,8 +16,8 @@ module ActiveAudit
16
16
  end
17
17
  end
18
18
 
19
- def before_create audit
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-audit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tariq Abughofa