activeaudit 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -25,6 +25,14 @@ and execute migration
25
25
  rake db:migrate
26
26
  ```
27
27
 
28
+ ### Update from 0.1.2 to 0.1.3
29
+
30
+ You have to installa new migration:
31
+ ```
32
+ rake active_audit_rails_engine:install:migrations
33
+ rake db:migrate
34
+ ```
35
+
28
36
  ## Usage
29
37
 
30
38
  In your model you have to include the mixin
@@ -1,14 +1,15 @@
1
1
  class ActiveAudit::Audit < ActiveRecord::Base
2
2
 
3
- attr_accessible :obj_id, :obj_type, :activity, :user_id
3
+ attr_accessible :obj_id, :obj_type, :activity, :user_id, :extras
4
4
  validates_presence_of :obj_id, :obj_type, :activity
5
+ serialize :extras, Hash
5
6
 
6
7
  if defined?(::Rails)
7
8
  if File.exists?(File.join(Rails.root.to_s,'app','models','concerns','active_audit','audit_concern.rb'))
8
- require File.join(Rails.root.to_s,'app','models','concerns','active_audit','audit_concern.rb')
9
- end
10
- if defined?(::ActiveAudit::AuditConcern)
11
- include ::ActiveAudit::AuditConcern
9
+ require_or_load File.join(Rails.root.to_s,'app','models','concerns','active_audit','audit_concern')
10
+ if defined?(ActiveAudit::AuditConcern)
11
+ include ActiveAudit::AuditConcern
12
+ end
12
13
  end
13
14
  end
14
15
 
@@ -0,0 +1,5 @@
1
+ class AddExtrasToActiveAudits < ActiveRecord::Migration
2
+ def change
3
+ add_column :audits, :extras, :text
4
+ end
5
+ end
@@ -4,7 +4,7 @@ module ActiveAudit
4
4
  module Rails
5
5
  class Engine < ::Rails::Engine
6
6
  initializer 'activeservice.autoload', :before => :set_autoload_paths do |app|
7
- app.config.autoload_paths += %W(#{app.config.root}/app/concerns/active_audit)
7
+ app.config.autoload_paths += %W(#{app.config.root}/app/models/concerns/active_audit)
8
8
  end
9
9
  #ActiveRecord::Base.class_eval do
10
10
  #include ActiveAudit::Logger
@@ -7,12 +7,15 @@ module ActiveAudit
7
7
 
8
8
  included do
9
9
 
10
+ has_many :audits, class_name: "ActiveAudit::Audit", as: :obj
11
+
10
12
  after_create :log_activity_on_create
11
13
  after_update :log_activity_on_update
12
14
  before_destroy :log_activity_on_destroy
13
15
 
14
16
  attr_accessible :audit_user_id
15
17
  attr_accessor :audit_user_id
18
+ attr_accessor :audit_extras
16
19
 
17
20
  @@_loggable_events = {}
18
21
 
@@ -28,7 +31,7 @@ module ActiveAudit
28
31
  @@_loggable_events.each do |k,v|
29
32
  next unless k.eql?(:create)
30
33
  if v.eql?(true)
31
- ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s
34
+ ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s, extras: audit_extras
32
35
  elsif v.is_a?(Array)
33
36
  log_event = false
34
37
  v.each do |field|
@@ -40,7 +43,7 @@ module ActiveAudit
40
43
  end
41
44
  end
42
45
  if log_event
43
- ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s
46
+ ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s, extras: audit_extras
44
47
  end
45
48
  end
46
49
  end
@@ -50,7 +53,7 @@ module ActiveAudit
50
53
  @@_loggable_events.each do |k,v|
51
54
  next if [:create,:destroy].include?(k)
52
55
  if k.eql?(:update) and v.eql?(true)
53
- ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s
56
+ ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s, extras: audit_extras
54
57
  else
55
58
  if v.is_a?(Array)
56
59
  log_event = false
@@ -63,7 +66,7 @@ module ActiveAudit
63
66
  end
64
67
  end
65
68
  if log_event
66
- ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s
69
+ ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s, extras: audit_extras
67
70
  end
68
71
  end
69
72
  end
@@ -73,7 +76,7 @@ module ActiveAudit
73
76
  def log_activity_on_destroy
74
77
  @@_loggable_events.each do |k,v|
75
78
  next unless k.eql?(:destroy)
76
- ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s
79
+ ActiveAudit::Audit.create obj_id: id, obj_type: self.class.to_s, user_id: audit_user_id, activity: k.to_s, extras: audit_extras
77
80
  end
78
81
  end
79
82
 
@@ -9,6 +9,7 @@ require 'active_audit/logger'
9
9
  require 'active_record'
10
10
  require 'faker'
11
11
  require './db/migrate/1_create_active_audits'
12
+ require './db/migrate/2_add_extras_to_active_audits'
12
13
 
13
14
  puts "Removing test database..."
14
15
  if File.exist? "spec/db/active_audit_test.sqlite3"
@@ -21,6 +22,7 @@ ActiveRecord::Base.establish_connection(
21
22
  puts "Creating test tables..."
22
23
  ActiveRecord::Base.connection.execute("CREATE TABLE `people`(`id` INTEGER PRIMARY KEY AUTOINCREMENT, `name` TEXT, `surname` TEXT, `email` TEXT, `age` INT, `created_at` DATETIME, `updated_at` DATETIME);")
23
24
  CreateActiveAudits.migrate :up
25
+ AddExtrasToActiveAudits.migrate :up
24
26
 
25
27
  RSpec.configure do |config|
26
28
  config.treat_symbols_as_metadata_keys_with_true_values = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeaudit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
@@ -133,6 +133,7 @@ extra_rdoc_files:
133
133
  files:
134
134
  - app/models/active_audit/audit.rb
135
135
  - db/migrate/1_create_active_audits.rb
136
+ - db/migrate/2_add_extras_to_active_audits.rb
136
137
  - lib/active_audit/engine.rb
137
138
  - lib/active_audit/logger.rb
138
139
  - lib/activeaudit.rb
@@ -157,7 +158,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
158
  version: '0'
158
159
  segments:
159
160
  - 0
160
- hash: 3583920372480114366
161
+ hash: 1962650347525140061
161
162
  required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  none: false
163
164
  requirements: