chrno_audit 0.2.4 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0062dcbf09cede00ed1653833974379aec8b57d
4
- data.tar.gz: 04895bc6278aec3259ed18d9612ddcb53a9d9e06
3
+ metadata.gz: fe0a4ec8f0e6ed3025f0d2189528eee044cfcebc
4
+ data.tar.gz: 9e1764234ae1cc8300df44d6e5915b7cecab433a
5
5
  SHA512:
6
- metadata.gz: e54826cdb9a5a549873c544f9325cbdb751ae9cfc8bd5b1ffb7cc9215ab6c0c6eab03fae334b5162981706b67067a0b42400ac8058fb8c7a7e8491761d0ba40f
7
- data.tar.gz: 4a1c88092ac240d6052b201ef3ed7d0c3bfefdf63b08dde907f16e67210627f200e30ee09a5bc8ed0ec664037d2b5ed1a2f29ee0a8b77a6f0df0e190d3c8f764
6
+ metadata.gz: ea081b2310d6e4afcbc3fb8dcc3f62009e3421edb12409a5d8763352a7d4ed89673b68690bde597f2fa69c07b95f4f66341e06222cb609f77afee23e9ae54807
7
+ data.tar.gz: 0d0d1c1086ed645fcde3f0370ba1bbf92ae55fc8b29c9ce9f927e96dbf0df76e96027c17bff137be2ecdcccf33d4f8eef9021dbafd9b209eadf8b68e2ea8be94
data/Gemfile.lock CHANGED
@@ -1,88 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chrno_audit (0.2.4)
4
+ chrno_audit (0.4.0)
5
5
  activerecord (>= 3.1)
6
- rails (>= 3.1)
7
6
 
8
7
  GEM
9
8
  remote: http://rubygems.org/
10
9
  specs:
11
- actionmailer (3.2.13)
12
- actionpack (= 3.2.13)
13
- mail (~> 2.5.3)
14
- actionpack (3.2.13)
15
- activemodel (= 3.2.13)
16
- activesupport (= 3.2.13)
10
+ activemodel (3.2.19)
11
+ activesupport (= 3.2.19)
17
12
  builder (~> 3.0.0)
18
- erubis (~> 2.7.0)
19
- journey (~> 1.0.4)
20
- rack (~> 1.4.5)
21
- rack-cache (~> 1.2)
22
- rack-test (~> 0.6.1)
23
- sprockets (~> 2.2.1)
24
- activemodel (3.2.13)
25
- activesupport (= 3.2.13)
26
- builder (~> 3.0.0)
27
- activerecord (3.2.13)
28
- activemodel (= 3.2.13)
29
- activesupport (= 3.2.13)
13
+ activerecord (3.2.19)
14
+ activemodel (= 3.2.19)
15
+ activesupport (= 3.2.19)
30
16
  arel (~> 3.0.2)
31
17
  tzinfo (~> 0.3.29)
32
- activeresource (3.2.13)
33
- activemodel (= 3.2.13)
34
- activesupport (= 3.2.13)
35
- activesupport (3.2.13)
36
- i18n (= 0.6.1)
18
+ activesupport (3.2.19)
19
+ i18n (~> 0.6, >= 0.6.4)
37
20
  multi_json (~> 1.0)
38
21
  arel (3.0.3)
39
22
  builder (3.0.4)
40
- erubis (2.7.0)
41
- hike (1.2.3)
42
- i18n (0.6.1)
43
- journey (1.0.4)
44
- json (1.8.1)
45
- mail (2.5.4)
46
- mime-types (~> 1.16)
47
- treetop (~> 1.4.8)
48
- mime-types (1.25.1)
23
+ i18n (0.7.0)
49
24
  multi_json (1.10.1)
50
- polyglot (0.3.5)
51
- rack (1.4.5)
52
- rack-cache (1.2)
53
- rack (>= 0.4)
54
- rack-ssl (1.3.4)
55
- rack
56
- rack-test (0.6.2)
57
- rack (>= 1.0)
58
- rails (3.2.13)
59
- actionmailer (= 3.2.13)
60
- actionpack (= 3.2.13)
61
- activerecord (= 3.2.13)
62
- activeresource (= 3.2.13)
63
- activesupport (= 3.2.13)
64
- bundler (~> 1.0)
65
- railties (= 3.2.13)
66
- railties (3.2.13)
67
- actionpack (= 3.2.13)
68
- activesupport (= 3.2.13)
69
- rack-ssl (~> 1.3.2)
70
- rake (>= 0.8.7)
71
- rdoc (~> 3.4)
72
- thor (>= 0.14.6, < 2.0)
73
- rake (10.4.2)
74
- rdoc (3.12.2)
75
- json (~> 1.4)
76
- sprockets (2.2.3)
77
- hike (~> 1.2)
78
- multi_json (~> 1.0)
79
- rack (~> 1.0)
80
- tilt (~> 1.1, != 1.3.0)
81
- thor (0.19.1)
82
- tilt (1.4.1)
83
- treetop (1.4.15)
84
- polyglot
85
- polyglot (>= 0.3.1)
86
25
  tzinfo (0.3.42)
87
26
 
88
27
  PLATFORMS
@@ -5,7 +5,7 @@
5
5
  #
6
6
  class ChrnoAudit::AuditRecord < ActiveRecord::Base
7
7
  # Имя таблицы с логами
8
- self.table_name = ChrnoAudit.config.table_name || "audit_log"
8
+ self.table_name = "audit_log"
9
9
 
10
10
  # Кто изменил?
11
11
  belongs_to :initiator, :polymorphic => true
@@ -14,10 +14,10 @@ class ChrnoAudit::AuditRecord < ActiveRecord::Base
14
14
  belongs_to :auditable, :polymorphic => true
15
15
 
16
16
  # Изменения
17
- serialize :diff, ChrnoAudit.config.serializer || Object
17
+ serialize :diff
18
18
 
19
19
  # Контекст
20
- serialize :context, ChrnoAudit.config.serializer || Object
20
+ serialize :context
21
21
 
22
22
  # Возвращает записи для заданного типа сущности.
23
23
  scope :for_type, -> *types { where( auditable_type: types.map { |t| t.class.model_name })}
data/chrno_audit.gemspec CHANGED
@@ -15,6 +15,5 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.required_ruby_version = ">= 1.9.3"
17
17
 
18
- s.add_runtime_dependency "rails", ">= 3.1"
19
18
  s.add_runtime_dependency "activerecord", ">= 3.1"
20
19
  end
data/lib/chrno_audit.rb CHANGED
@@ -1,33 +1,38 @@
1
1
  # encoding: utf-8
2
- if Rails.version.to_i >= 4
2
+ if !defined?( Rails ) || Rails.version.to_i >= 4
3
3
  # В четвёртых рельсах обзерверы вынесены в джем
4
4
  gem "rails-observers", "~> 0.1.1"
5
5
  require "rails-observers"
6
6
 
7
7
  # Хак для eager load: по умолчанию класс ActiveRecord::Observer грузится ПОСЛЕ
8
8
  # того грузятся модели из app/models при eager_load = true, что приводит к ошибке
9
- # если рядом с моделями лежат обзервере. Поэтому грузим определение класса сразу.
9
+ # если рядом с моделями лежат обзерверы. Поэтому грузим определение класса сразу.
10
10
  require "rails/observers/activerecord/active_record"
11
11
  end
12
12
 
13
- require "active_support/configurable"
14
- require "chrno_audit/version"
15
-
16
13
  module ChrnoAudit
17
- include ActiveSupport::Configurable
14
+ require "chrno_audit/version"
15
+ end
18
16
 
19
- class Engine < Rails::Engine
20
- initializer "chrno_audit.initialize", :before => :load_active_support do
21
- require "chrno_audit/action_controller_concern"
22
- require "chrno_audit/active_record_concern"
17
+ ActiveSupport.on_load( :action_controller ) do
18
+ require "chrno_audit/action_controller_concern"
19
+ include ChrnoAudit::ActionControllerConcern
20
+ end
21
+
22
+ ActiveSupport.on_load( :active_record ) do
23
+ require "chrno_audit/active_record_concern"
24
+ include ChrnoAudit::ActiveRecordConcern
25
+ end
23
26
 
24
- ActiveSupport.on_load( :action_controller ) do
25
- include ChrnoAudit::ActionControllerConcern
26
- end
27
+ # Если мы запускаемся в контексте рельс, то грузим Engine
28
+ if defined?( Rails ) && defined?( Rails::Engine )
29
+ require "chrno_audit/engine"
27
30
 
28
- ActiveSupport.on_load( :active_record ) do
29
- include ChrnoAudit::ActiveRecordConcern
30
- end
31
+ # Иначе подключаем модели руками
32
+ else
33
+ ActiveSupport.on_load( :active_record ) do
34
+ Dir.glob( File.join( File.expand_path( "../../app/models", __FILE__ ), "**", "*.rb" )).each do |file|
35
+ require file
31
36
  end
32
37
  end
33
38
  end
@@ -32,7 +32,7 @@ module ChrnoAudit
32
32
  def audit( *fields )
33
33
  # Если таблицы ещё нет, ничего не делаем (полезно для миграций)
34
34
  unless table_exists?
35
- Rails.logger.warn "Audit: try to audit model [#{name}] with non-existent table"
35
+ self.logger.warn "Audit: try to audit model [#{name}] with non-existent table" if self.logger
36
36
  return
37
37
  end
38
38
 
@@ -71,8 +71,10 @@ module ChrnoAudit
71
71
  self.auditable_options = options
72
72
 
73
73
  # Проверки
74
- Rails.logger.warn "Audit: no fields to audit" if self.auditable_fields.empty?
75
- Rails.logger.warn "Audit: no actions to audit" if self.auditable_actions.empty?
74
+ if self.logger
75
+ self.logger.warn "Audit: no fields to audit" if self.auditable_fields.empty?
76
+ self.logger.warn "Audit: no actions to audit" if self.auditable_actions.empty?
77
+ end
76
78
  end
77
79
  end
78
80
  end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+ module ChrnoAudit
3
+ class Engine < Rails::Engine
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
  module ChrnoAudit
3
3
  # Версия гема
4
- VERSION = "0.2.4"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Вот пример кода, который может использоваться в контроллере:
7
7
 
8
- def history$
8
+ def history
9
9
  @page = Page.find params[:id]
10
10
  @history = ChrnoAudit::AuditRecord.for_object( @page ).order( "created_at DESC" )
11
11
  end
@@ -1,8 +1,7 @@
1
1
  # encoding: utf-8
2
- ChrnoAudit.configure do |config|
3
- # Имя таблицы с событиями
4
- # config.table_name = "audit_log"
5
2
 
6
- # Кодер для сериализации diff'а
7
- # config.serializer = ActiveRecord::Coders::YAMLColumn
8
- end
3
+ # Имя таблицы с событиями
4
+ # ChrnoAudit::AuditRecord.table_name = "audit_log"
5
+
6
+ # Кодер для сериализации diff'а
7
+ # ChrnoAudit::AuditRecord.serialize :diff, ActiveRecord::Coders::YAMLColumn
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrno_audit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Diachkov
@@ -10,20 +10,6 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '3.1'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '3.1'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: activerecord
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -53,11 +39,11 @@ files:
53
39
  - TODO
54
40
  - app/models/chrno_audit/audit_observer.rb
55
41
  - app/models/chrno_audit/audit_record.rb
56
- - chrno_audit-0.4.0.gem
57
42
  - chrno_audit.gemspec
58
43
  - lib/chrno_audit.rb
59
44
  - lib/chrno_audit/action_controller_concern.rb
60
45
  - lib/chrno_audit/active_record_concern.rb
46
+ - lib/chrno_audit/engine.rb
61
47
  - lib/chrno_audit/version.rb
62
48
  - lib/generators/chrno_audit/install_generator.rb
63
49
  - lib/generators/chrno_audit/templates/README
Binary file