trackzor 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +0 -12
- data/Rakefile +3 -3
- data/generators/trackzor_migration/templates/migration.rb +1 -1
- data/lib/trackzor.rb +22 -13
- data/trackzor.gemspec +6 -6
- metadata +5 -16
- data/pkg/trackzor-0.1.0/CHANGELOG +0 -0
- data/pkg/trackzor-0.1.0/Manifest +0 -20
- data/pkg/trackzor-0.1.0/README.rdoc +0 -12
- data/pkg/trackzor-0.1.0/Rakefile +0 -14
- data/pkg/trackzor-0.1.0/generators/trackzor_migration/templates/migration.rb +0 -11
- data/pkg/trackzor-0.1.0/generators/trackzor_migration/trackzor_migration_generator.rb +0 -7
- data/pkg/trackzor-0.1.0/init.rb +0 -1
- data/pkg/trackzor-0.1.0/lib/trackzor.rb +0 -47
- data/pkg/trackzor-0.1.0/trackzor.gemspec +0 -30
- data/pkg/trackzor-0.1.0.gem +0 -0
- data/pkg/trackzor-0.1.0.tar.gz +0 -0
data/Manifest
CHANGED
@@ -6,15 +6,3 @@ generators/trackzor_migration/templates/migration.rb
|
|
6
6
|
generators/trackzor_migration/trackzor_migration_generator.rb
|
7
7
|
init.rb
|
8
8
|
lib/trackzor.rb
|
9
|
-
pkg/trackzor-0.1.0.gem
|
10
|
-
pkg/trackzor-0.1.0.tar.gz
|
11
|
-
pkg/trackzor-0.1.0/CHANGELOG
|
12
|
-
pkg/trackzor-0.1.0/Manifest
|
13
|
-
pkg/trackzor-0.1.0/README.rdoc
|
14
|
-
pkg/trackzor-0.1.0/Rakefile
|
15
|
-
pkg/trackzor-0.1.0/generators/trackzor_migration/templates/migration.rb
|
16
|
-
pkg/trackzor-0.1.0/generators/trackzor_migration/trackzor_migration_generator.rb
|
17
|
-
pkg/trackzor-0.1.0/init.rb
|
18
|
-
pkg/trackzor-0.1.0/lib/trackzor.rb
|
19
|
-
pkg/trackzor-0.1.0/trackzor.gemspec
|
20
|
-
trackzor.gemspec
|
data/Rakefile
CHANGED
@@ -2,9 +2,9 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('trackzor', '0.1.
|
6
|
-
gem.description = "Track ATTR_updated_at and ATTR_updated_by
|
7
|
-
gem.url = "http://
|
5
|
+
Echoe.new('trackzor', '0.1.1') do |gem|
|
6
|
+
gem.description = "Track ATTR_updated_at and ATTR_updated_by"
|
7
|
+
gem.url = "http://github.com/corneldm/trackzor"
|
8
8
|
gem.author = "David Cornelius"
|
9
9
|
gem.email = "david.cornelius@bluefishwireless.net"
|
10
10
|
gem.ignore_pattern = ["tmp/*", "script/*"]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class Trackzorify<%= class_name.pluralize %> < ActiveRecord::Migration
|
2
2
|
def self.up<% args.each do |arg| %>
|
3
3
|
add_column :<%= table_name %>, :<%= "#{arg}_updated_at" %>, :datetime
|
4
|
-
add_column :<%= table_name %>, :<%= "#{arg}_updated_by" %>, :
|
4
|
+
add_column :<%= table_name %>, :<%= "#{arg}_updated_by" %>, :integer<% end %>
|
5
5
|
end
|
6
6
|
|
7
7
|
def self.down<% args.each do |arg| %>
|
data/lib/trackzor.rb
CHANGED
@@ -4,27 +4,36 @@ module Trackzor
|
|
4
4
|
end
|
5
5
|
|
6
6
|
module ClassMethods
|
7
|
-
def trackzored
|
8
|
-
|
9
|
-
|
7
|
+
def trackzored(options = {})
|
8
|
+
if options[:only]
|
9
|
+
except = self.column_names - options[:only].flatten.map(&:to_s)
|
10
|
+
else
|
11
|
+
except = [self.primary_key, inheritance_column, 'lock_version', 'created_at', 'updated_at']
|
12
|
+
except |= Array(options[:except]).collect(&:to_s) if options[:except]
|
13
|
+
end
|
14
|
+
|
15
|
+
(self.column_names - except).select{|column| column =~ /_updated_by/ }.each do |col|
|
16
|
+
belongs_to "#{col.split('_updated_by')[0]}_source".to_sym, :class_name => 'User', :foreign_key => col
|
10
17
|
end
|
11
18
|
|
12
19
|
validate do |record|
|
13
20
|
user = Thread.current[:trackzor_user] || Thread.current[:acts_as_audited_user]
|
14
21
|
|
15
22
|
record.changes.keys.each do |attr|
|
16
|
-
|
17
|
-
|
23
|
+
unless except.include?(attr)
|
24
|
+
time_column = "#{attr}_updated_at"
|
25
|
+
user_association = "#{attr}_source"
|
18
26
|
|
19
|
-
|
20
|
-
|
21
|
-
|
27
|
+
if record.respond_to?(time_column.to_sym)
|
28
|
+
record.send("#{time_column}=".to_sym, Time.now)
|
29
|
+
end
|
22
30
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
31
|
+
if record.respond_to?(user_association.to_sym)
|
32
|
+
if user
|
33
|
+
record.send("#{user_association}=".to_sym, user)
|
34
|
+
else
|
35
|
+
record.errors.add("#{attr}_updated_by", "requires Trackzor user to be set")
|
36
|
+
end
|
28
37
|
end
|
29
38
|
end
|
30
39
|
end
|
data/trackzor.gemspec
CHANGED
@@ -2,21 +2,21 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{trackzor}
|
5
|
-
s.version = "0.1.
|
5
|
+
s.version = "0.1.1"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["David Cornelius"]
|
9
|
-
s.date = %q{2010-01-
|
10
|
-
s.description = %q{Track ATTR_updated_at and ATTR_updated_by
|
9
|
+
s.date = %q{2010-01-13}
|
10
|
+
s.description = %q{Track ATTR_updated_at and ATTR_updated_by}
|
11
11
|
s.email = %q{david.cornelius@bluefishwireless.net}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/trackzor.rb"]
|
13
|
-
s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "generators/trackzor_migration/templates/migration.rb", "generators/trackzor_migration/trackzor_migration_generator.rb", "init.rb", "lib/trackzor.rb", "
|
14
|
-
s.homepage = %q{http://
|
13
|
+
s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "generators/trackzor_migration/templates/migration.rb", "generators/trackzor_migration/trackzor_migration_generator.rb", "init.rb", "lib/trackzor.rb", "trackzor.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/corneldm/trackzor}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trackzor", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{trackzor}
|
18
18
|
s.rubygems_version = %q{1.3.5}
|
19
|
-
s.summary = %q{Track ATTR_updated_at and ATTR_updated_by
|
19
|
+
s.summary = %q{Track ATTR_updated_at and ATTR_updated_by}
|
20
20
|
|
21
21
|
if s.respond_to? :specification_version then
|
22
22
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trackzor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cornelius
|
@@ -9,11 +9,11 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-13 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
16
|
-
description: Track ATTR_updated_at and ATTR_updated_by
|
16
|
+
description: Track ATTR_updated_at and ATTR_updated_by
|
17
17
|
email: david.cornelius@bluefishwireless.net
|
18
18
|
executables: []
|
19
19
|
|
@@ -32,20 +32,9 @@ files:
|
|
32
32
|
- generators/trackzor_migration/trackzor_migration_generator.rb
|
33
33
|
- init.rb
|
34
34
|
- lib/trackzor.rb
|
35
|
-
- pkg/trackzor-0.1.0.gem
|
36
|
-
- pkg/trackzor-0.1.0.tar.gz
|
37
|
-
- pkg/trackzor-0.1.0/CHANGELOG
|
38
|
-
- pkg/trackzor-0.1.0/Manifest
|
39
|
-
- pkg/trackzor-0.1.0/README.rdoc
|
40
|
-
- pkg/trackzor-0.1.0/Rakefile
|
41
|
-
- pkg/trackzor-0.1.0/generators/trackzor_migration/templates/migration.rb
|
42
|
-
- pkg/trackzor-0.1.0/generators/trackzor_migration/trackzor_migration_generator.rb
|
43
|
-
- pkg/trackzor-0.1.0/init.rb
|
44
|
-
- pkg/trackzor-0.1.0/lib/trackzor.rb
|
45
|
-
- pkg/trackzor-0.1.0/trackzor.gemspec
|
46
35
|
- trackzor.gemspec
|
47
36
|
has_rdoc: true
|
48
|
-
homepage: http://
|
37
|
+
homepage: http://github.com/corneldm/trackzor
|
49
38
|
licenses: []
|
50
39
|
|
51
40
|
post_install_message:
|
@@ -76,6 +65,6 @@ rubyforge_project: trackzor
|
|
76
65
|
rubygems_version: 1.3.5
|
77
66
|
signing_key:
|
78
67
|
specification_version: 3
|
79
|
-
summary: Track ATTR_updated_at and ATTR_updated_by
|
68
|
+
summary: Track ATTR_updated_at and ATTR_updated_by
|
80
69
|
test_files: []
|
81
70
|
|
File without changes
|
data/pkg/trackzor-0.1.0/Manifest
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
CHANGELOG
|
2
|
-
Manifest
|
3
|
-
README.rdoc
|
4
|
-
Rakefile
|
5
|
-
generators/trackzor_migration/templates/migration.rb
|
6
|
-
generators/trackzor_migration/trackzor_migration_generator.rb
|
7
|
-
init.rb
|
8
|
-
lib/trackzor.rb
|
9
|
-
pkg/trackzor-0.1.0.gem
|
10
|
-
pkg/trackzor-0.1.0.tar.gz
|
11
|
-
pkg/trackzor-0.1.0/CHANGELOG
|
12
|
-
pkg/trackzor-0.1.0/Manifest
|
13
|
-
pkg/trackzor-0.1.0/README.rdoc
|
14
|
-
pkg/trackzor-0.1.0/Rakefile
|
15
|
-
pkg/trackzor-0.1.0/generators/trackzor_migration/templates/migration.rb
|
16
|
-
pkg/trackzor-0.1.0/generators/trackzor_migration/trackzor_migration_generator.rb
|
17
|
-
pkg/trackzor-0.1.0/init.rb
|
18
|
-
pkg/trackzor-0.1.0/lib/trackzor.rb
|
19
|
-
pkg/trackzor-0.1.0/trackzor.gemspec
|
20
|
-
trackzor.gemspec
|
@@ -1,12 +0,0 @@
|
|
1
|
-
= Quick Start
|
2
|
-
|
3
|
-
Add "trackzored" to your model. By convention, any attribute that also has [ATTR]_updated_at or [ATTR]_updated_by will be tracked. If [ATTR]_updated_by is present, it is required by a validator.
|
4
|
-
|
5
|
-
Use the trackzor_migration generator to quickly add columns:
|
6
|
-
<tt>script/generate trackzor_migration User email phone_number</tt>
|
7
|
-
This will create a migration for adding email_updated_at, email_updated_by, phone_number_updated_at, and phone_number_updated_by columns.
|
8
|
-
|
9
|
-
To set the current user:
|
10
|
-
<tt>Trackzor.as_user(user_obj) do
|
11
|
-
...
|
12
|
-
end</tt>
|
data/pkg/trackzor-0.1.0/Rakefile
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'rake'
|
3
|
-
require 'echoe'
|
4
|
-
|
5
|
-
Echoe.new('trackzor', '0.1.0') do |gem|
|
6
|
-
gem.description = "Track ATTR_updated_at and ATTR_updated_by with ease."
|
7
|
-
gem.url = "http://bitbucket.org/corneldm/trackzor"
|
8
|
-
gem.author = "David Cornelius"
|
9
|
-
gem.email = "david.cornelius@bluefishwireless.net"
|
10
|
-
gem.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
-
gem.development_dependencies = []
|
12
|
-
end
|
13
|
-
|
14
|
-
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
@@ -1,11 +0,0 @@
|
|
1
|
-
class Trackzorify<%= class_name.pluralize %> < ActiveRecord::Migration
|
2
|
-
def self.up<% args.each do |arg| %>
|
3
|
-
add_column :<%= table_name %>, :<%= "#{arg}_updated_at" %>, :datetime
|
4
|
-
add_column :<%= table_name %>, :<%= "#{arg}_updated_by" %>, :string<% end %>
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.down<% args.each do |arg| %>
|
8
|
-
remove_column :<%= table_name %>, :<%= "#{arg}_updated_at" %>
|
9
|
-
remove_column :<%= table_name %>, :<%= "#{arg}_updated_by" %><% end %>
|
10
|
-
end
|
11
|
-
end
|
data/pkg/trackzor-0.1.0/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'trackzor'
|
@@ -1,47 +0,0 @@
|
|
1
|
-
module Trackzor
|
2
|
-
def self.included(base)
|
3
|
-
base.extend ClassMethods
|
4
|
-
end
|
5
|
-
|
6
|
-
module ClassMethods
|
7
|
-
def trackzored
|
8
|
-
self.columns.select{|column| column.name =~ /_updated_by/ }.each do |col|
|
9
|
-
belongs_to "#{col.name.split('_updated_by')[0]}_source".to_sym, :class_name => 'User', :foreign_key => col.name
|
10
|
-
end
|
11
|
-
|
12
|
-
validate do |record|
|
13
|
-
user = Thread.current[:trackzor_user] || Thread.current[:acts_as_audited_user]
|
14
|
-
|
15
|
-
record.changes.keys.each do |attr|
|
16
|
-
time_column = "#{attr}_updated_at"
|
17
|
-
user_association = "#{attr}_source"
|
18
|
-
|
19
|
-
if record.respond_to?(time_column.to_sym)
|
20
|
-
record.send("#{time_column}=".to_sym, Time.now)
|
21
|
-
end
|
22
|
-
|
23
|
-
if record.respond_to?(user_association.to_sym)
|
24
|
-
if user
|
25
|
-
record.send("#{user_association}=".to_sym, user)
|
26
|
-
else
|
27
|
-
record.errors.add("#{attr}_updated_by", "requires Trackzor.user or Audit.user to be set")
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# All X attribute changes where X_updated_by exists will be recorded as made by +user+.
|
36
|
-
def self.as_user(user, &block)
|
37
|
-
Thread.current[:trackzor_user] = user
|
38
|
-
|
39
|
-
yield
|
40
|
-
|
41
|
-
Thread.current[:trackzor_user] = nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
class ActiveRecord::Base
|
46
|
-
include Trackzor
|
47
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = %q{trackzor}
|
5
|
-
s.version = "0.1.0"
|
6
|
-
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
-
s.authors = ["David Cornelius"]
|
9
|
-
s.date = %q{2010-01-08}
|
10
|
-
s.description = %q{Track ATTR_updated_at and ATTR_updated_by with ease.}
|
11
|
-
s.email = %q{david.cornelius@bluefishwireless.net}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/trackzor.rb"]
|
13
|
-
s.files = ["CHANGELOG", "Manifest", "README.rdoc", "Rakefile", "generators/trackzor_migration/templates/migration.rb", "generators/trackzor_migration/trackzor_migration_generator.rb", "init.rb", "lib/trackzor.rb", "trackzor.gemspec"]
|
14
|
-
s.homepage = %q{http://github.com/corneldm/trackzor}
|
15
|
-
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Trackzor", "--main", "README.rdoc"]
|
16
|
-
s.require_paths = ["lib"]
|
17
|
-
s.rubyforge_project = %q{trackzor}
|
18
|
-
s.rubygems_version = %q{1.3.5}
|
19
|
-
s.summary = %q{Track ATTR_updated_at and ATTR_updated_by with ease.}
|
20
|
-
|
21
|
-
if s.respond_to? :specification_version then
|
22
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
-
s.specification_version = 3
|
24
|
-
|
25
|
-
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
-
else
|
27
|
-
end
|
28
|
-
else
|
29
|
-
end
|
30
|
-
end
|
data/pkg/trackzor-0.1.0.gem
DELETED
Binary file
|
data/pkg/trackzor-0.1.0.tar.gz
DELETED
Binary file
|