ar-audit-tracer 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1,2 +1 @@
1
- rvm_gemset_create_on_use_flag=1
2
- rvm gemset use 1.9.2@ar-audit-tracer
1
+ rvm use 1.9.3-p125
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ gemfile:
7
+ - gemfiles/rails3_0.gemfile
8
+ - gemfiles/rails3_1.gemfile
9
+ - gemfiles/rails3_2.gemfile
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in lorem.gemspec
4
- gemspec
3
+ #gemspec
4
+
5
+ #gem 'activerecord', '~> 3.0.3'
6
+ #gem 'activerecord', '~> 3.1.0'
7
+ gem 'activerecord', '~> 3.2.0'
8
+
9
+ group :test do
10
+ gem 'rake'
11
+ gem 'sqlite3'
12
+ end
@@ -1,31 +1,29 @@
1
- PATH
2
- remote: .
3
- specs:
4
- ar-audit-tracer (0.2.0)
5
-
6
1
  GEM
7
2
  remote: http://rubygems.org/
8
3
  specs:
9
- activemodel (3.0.4)
10
- activesupport (= 3.0.4)
11
- builder (~> 2.1.2)
12
- i18n (~> 0.4)
13
- activerecord (3.0.4)
14
- activemodel (= 3.0.4)
15
- activesupport (= 3.0.4)
16
- arel (~> 2.0.2)
17
- tzinfo (~> 0.3.23)
18
- activesupport (3.0.4)
19
- arel (2.0.8)
20
- builder (2.1.2)
21
- i18n (0.5.0)
22
- sqlite3 (1.3.3)
23
- tzinfo (0.3.24)
4
+ activemodel (3.2.1)
5
+ activesupport (= 3.2.1)
6
+ builder (~> 3.0.0)
7
+ activerecord (3.2.1)
8
+ activemodel (= 3.2.1)
9
+ activesupport (= 3.2.1)
10
+ arel (~> 3.0.0)
11
+ tzinfo (~> 0.3.29)
12
+ activesupport (3.2.1)
13
+ i18n (~> 0.6)
14
+ multi_json (~> 1.0)
15
+ arel (3.0.0)
16
+ builder (3.0.0)
17
+ i18n (0.6.0)
18
+ multi_json (1.0.4)
19
+ rake (0.9.2.2)
20
+ sqlite3 (1.3.5)
21
+ tzinfo (0.3.31)
24
22
 
25
23
  PLATFORMS
26
24
  ruby
27
25
 
28
26
  DEPENDENCIES
29
- activerecord
30
- ar-audit-tracer!
27
+ activerecord (~> 3.2.0)
28
+ rake
31
29
  sqlite3
@@ -1,11 +1,14 @@
1
1
  = ar-audit-tracer
2
2
 
3
+ {<img src="https://secure.travis-ci.org/verticonaut/ar-audit-tracer.png" />}[http://travis-ci.org/verticonaut/ar-audit-tracer]
3
4
 
4
5
  == Summary
5
6
 
6
7
  <i>ar-audit-tracer</i> patches ActiveRecord so modifiers of a record can be traked on saving (insert/update).
7
8
  It works exactly like 'timestamps' (see usage below).
8
9
 
10
+ The new version 1.0.0 works now for Rails 3.0, 3.1 and 3.2 and is tested with Ruby 1.8.7, 1.9.2 and 1.9.3.
11
+
9
12
 
10
13
  == Usage
11
14
 
@@ -5,7 +5,7 @@ require 'ar-audit-tracer/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ar-audit-tracer}
8
- s.version = "0.2.0"
8
+ s.version = ArAuditTracer::VERSION
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Martin Schweizer"]
11
11
  s.email = %q{martin@verticonaut.me}
@@ -13,9 +13,12 @@ Gem::Specification.new do |s|
13
13
  s.summary = %q{Track creator/modifiers of you AR Models similar to timestamps.}
14
14
  s.description = %q{Handles ActiveRecord authors in the same way as timstamps.}
15
15
 
16
- s.add_development_dependency "activerecord"
17
- s.add_development_dependency "sqlite3"
16
+ s.add_dependency "activerecord", "~> 3.0.3"
18
17
 
18
+ s.add_development_dependency "activerecord"
19
+ s.add_development_dependency "sqlite3"
20
+
21
+ s.rdoc_options << '--charset' << 'UTF-8' << '--line-numbers'
19
22
  s.files = `git ls-files`.split("\n")
20
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 3.0.3'
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ gem 'sqlite3'
8
+ end
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 3.1.0'
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ gem 'sqlite3'
8
+ end
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'activerecord', '~> 3.2.0'
4
+
5
+ group :test do
6
+ gem 'rake'
7
+ gem 'sqlite3'
8
+ end
@@ -1,63 +1,7 @@
1
+ # encoding: utf-8
1
2
  require 'concern/audit/author'
2
3
 
3
- # ActiveRecordAuthors
4
4
  module ActiveRecord
5
- module ConnectionAdapters
6
-
7
- class TableDefinition
8
-
9
- # Creates author columns ...
10
- #
11
- # @param Symbol type The desired type for the columns, defaults to :string
12
- # @param Hash *args Column options from rails
13
- def authors(type=:string, *args)
14
- options = args.extract_options!
15
- column(:created_by, type, options)
16
- column(:updated_by, type, options)
17
- end
18
-
19
-
20
- end
21
-
22
- class Table
23
- # Adds author (created_by and updated_by) columns to the table
24
- # ===== Example
25
- # t.authors
26
- #
27
- # @param Symbol type The desired type for the columns, defaults to :string
28
- # @see SchemaStatements#add_authors
29
- def authors(type=:string)
30
- @base.add_authors(@table_name, type)
31
- end
32
-
33
- # Removes the author columns (created_by and updated_by) from the table.
34
- # ===== Example
35
- # t.remove_authors
36
- def remove_authors
37
- @base.remove_authors(@table_name)
38
- end
39
-
40
- end
41
-
42
- module SchemaStatements
43
- # Adds author columns (created_by and updated_by) to the named table.
44
- # ===== Examples
45
- # add_authors(:suppliers)
46
- def add_authors(table_name, type=:string)
47
- add_column table_name, :created_by, type
48
- add_column table_name, :updated_by, type
49
- end
50
-
51
- # Removes the author columns (created_by and updated_by) from the table definition.
52
- # ===== Examples
53
- # remove_authors(:suppliers)
54
- def remove_authors(table_name)
55
- remove_column table_name, :updated_by
56
- remove_column table_name, :created_by
57
- end
58
- end
59
-
60
- end
61
5
 
62
6
  # = Active Record Author
63
7
  #
@@ -72,18 +16,24 @@ module ActiveRecord
72
16
  extend ActiveSupport::Concern
73
17
 
74
18
  included do
75
- class_inheritable_accessor :record_authors, :instance_writer => false
19
+ class_attribute :record_authors
76
20
  self.record_authors = true
77
21
  end
78
22
 
23
+ def initialize_dup(other)
24
+ clear_author_attributes
25
+ end
26
+
79
27
  private
80
28
 
81
29
  def create #:nodoc:
82
- if record_authors
30
+ if self.record_authors
83
31
  current_author = Concern::Audit::Author.current
84
32
 
85
33
  all_author_attributes.each do |column|
86
- write_attribute(column.to_s, current_author) if respond_to?(column) && self.send(column).nil?
34
+ if respond_to?(column) && self.send(column).nil?
35
+ write_attribute(column.to_s, current_author)
36
+ end
87
37
  end
88
38
  end
89
39
 
@@ -104,13 +54,21 @@ module ActiveRecord
104
54
  end
105
55
 
106
56
  def should_record_authors?
107
- record_authors && (!partial_updates? || changed?)
57
+ self.record_authors && (!partial_updates? || changed? || (attributes.keys & self.class.serialized_attributes.keys).present?)
108
58
  end
109
59
 
110
60
  def author_attributes_for_update_in_model
111
61
  author_attributes_for_update.select { |c| respond_to?(c) }
112
62
  end
113
63
 
64
+ def author_attributes_for_create_in_model
65
+ author_attributes_for_create.select { |c| respond_to?(c) }
66
+ end
67
+
68
+ def all_author_attributes
69
+ author_attributes_for_create + author_attributes_for_update
70
+ end
71
+
114
72
  def author_attributes_for_update #:nodoc:
115
73
  [:updated_by]
116
74
  end
@@ -119,15 +77,83 @@ module ActiveRecord
119
77
  [:created_by]
120
78
  end
121
79
 
122
- def all_author_attributes #:nodoc:
123
- author_attributes_for_create + author_attributes_for_update
80
+ def all_author_attributes_in_model
81
+ author_attributes_for_create_in_model + author_attributes_for_update_in_model
82
+ end
83
+
84
+ # Clear attributes and changed_attributes
85
+ def clear_author_attributes
86
+ all_author_attributes_in_model.each do |attribute_name|
87
+ self[attribute_name] = nil
88
+ changed_attributes.delete(attribute_name)
89
+ end
124
90
  end
125
91
 
126
92
  end
127
93
 
94
+
95
+
96
+ module ConnectionAdapters
97
+ module SchemaStatements
98
+ # Adds author columns (created_by and updated_by) to the named table.
99
+ # ===== Examples
100
+ # add_authors(:suppliers)
101
+ def add_authors(table_name, type=:string)
102
+ add_column table_name, :created_by, type, :null => false
103
+ add_column table_name, :updated_by, type, :null => false
104
+ end
105
+
106
+ # Removes the author columns (created_by and updated_by) from the table definition.
107
+ # ===== Examples
108
+ # remove_authors(:suppliers)
109
+ def remove_authors(table_name)
110
+ remove_column table_name, :updated_by
111
+ remove_column table_name, :created_by
112
+ end
113
+ end
114
+
115
+
116
+ class TableDefinition
117
+
118
+ # Creates author columns ...
119
+ #
120
+ # @param Symbol type The desired type for the columns, defaults to :string
121
+ # @param Hash *args Column options from rails
122
+ def authors(type=:string, *args)
123
+ options = args.extract_options!
124
+ column(:created_by, type, options)
125
+ column(:updated_by, type, options)
126
+ end
127
+
128
+ end
129
+
130
+ class Table
131
+ # Adds author (created_by and updated_by) columns to the table
132
+ # ===== Example
133
+ # t.authors
134
+ #
135
+ # @param Symbol type The desired type for the columns, defaults to :string
136
+ # @see SchemaStatements#add_authors
137
+ def authors(type=:string)
138
+ @base.add_authors(@table_name, type)
139
+ end
140
+
141
+ # Removes the author columns (created_by and updated_by) from the table.
142
+ # ===== Example
143
+ # t.remove_authors
144
+ def remove_authors
145
+ @base.remove_authors(@table_name)
146
+ end
147
+
148
+ end
149
+
150
+ end
151
+
152
+
128
153
  Base.class_eval do
129
154
  include Author
130
155
  end
131
156
 
132
157
  end
133
158
 
159
+
@@ -1,3 +1,3 @@
1
1
  module ArAuditTracer
2
- VERSION = '0.2.0'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module Concern
2
4
  module Audit
3
5
  module Author
@@ -1,7 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'fileutils'
4
- require "active_record"
4
+ require 'active_record'
5
5
  require 'logger'
6
6
 
7
7
  # ------------------------------------------------------
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: ar-audit-tracer
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Martin Schweizer
@@ -10,31 +10,41 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-18 00:00:00 +01:00
14
- default_executable:
13
+ date: 2012-02-17 00:00:00 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: activerecord
18
17
  prerelease: false
19
18
  requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 3.0.3
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: activerecord
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
20
30
  none: false
21
31
  requirements:
22
32
  - - ">="
23
33
  - !ruby/object:Gem::Version
24
34
  version: "0"
25
35
  type: :development
26
- version_requirements: *id001
36
+ version_requirements: *id002
27
37
  - !ruby/object:Gem::Dependency
28
38
  name: sqlite3
29
39
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
40
+ requirement: &id003 !ruby/object:Gem::Requirement
31
41
  none: false
32
42
  requirements:
33
43
  - - ">="
34
44
  - !ruby/object:Gem::Version
35
45
  version: "0"
36
46
  type: :development
37
- version_requirements: *id002
47
+ version_requirements: *id003
38
48
  description: Handles ActiveRecord authors in the same way as timstamps.
39
49
  email: martin@verticonaut.me
40
50
  executables: []
@@ -47,12 +57,16 @@ files:
47
57
  - .document
48
58
  - .gitignore
49
59
  - .rvmrc
60
+ - .travis.yml
50
61
  - Gemfile
51
62
  - Gemfile.lock
52
63
  - LICENSE
53
64
  - README.rdoc
54
65
  - Rakefile
55
66
  - ar-audit-tracer.gemspec
67
+ - gemfiles/rails3_0.gemfile
68
+ - gemfiles/rails3_1.gemfile
69
+ - gemfiles/rails3_2.gemfile
56
70
  - lib/ar-audit-tracer.rb
57
71
  - lib/ar-audit-tracer/version.rb
58
72
  - lib/concern/audit/author.rb
@@ -61,13 +75,14 @@ files:
61
75
  - test/resources/models.rb
62
76
  - test/resources/schema.rb
63
77
  - test/test_ar-audit-tracer.rb
64
- has_rdoc: true
65
78
  homepage: http://github.com/verticonaut/ar-audit-tracer
66
79
  licenses: []
67
80
 
68
81
  post_install_message:
69
- rdoc_options: []
70
-
82
+ rdoc_options:
83
+ - --charset
84
+ - UTF-8
85
+ - --line-numbers
71
86
  require_paths:
72
87
  - lib
73
88
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -85,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
100
  requirements: []
86
101
 
87
102
  rubyforge_project:
88
- rubygems_version: 1.5.2
103
+ rubygems_version: 1.8.15
89
104
  signing_key:
90
105
  specification_version: 3
91
106
  summary: Track creator/modifiers of you AR Models similar to timestamps.