trackzor 0.1.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.
data/CHANGELOG ADDED
File without changes
data/Manifest ADDED
@@ -0,0 +1,20 @@
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
data/README.rdoc ADDED
@@ -0,0 +1,12 @@
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
+ script/generate trackzor_migration User email phone_number
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
+ Trackzor.as_user(user_obj) do
11
+ ...
12
+ end
data/Rakefile ADDED
@@ -0,0 +1,14 @@
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 }
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,7 @@
1
+ class TrackzorMigrationGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'migration.rb', 'db/migrate', {:migration_file_name => "trackzorify_#{table_name}"}
5
+ end
6
+ end
7
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'trackzor'
data/lib/trackzor.rb ADDED
@@ -0,0 +1,47 @@
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
File without changes
@@ -0,0 +1,20 @@
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
@@ -0,0 +1,12 @@
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>
@@ -0,0 +1,14 @@
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 }
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,7 @@
1
+ class TrackzorMigrationGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.migration_template 'migration.rb', 'db/migrate', {:migration_file_name => "trackzorify_#{table_name}"}
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require 'trackzor'
@@ -0,0 +1,47 @@
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
@@ -0,0 +1,30 @@
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
Binary file
Binary file
data/trackzor.gemspec ADDED
@@ -0,0 +1,30 @@
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", "pkg/trackzor-0.1.0.gem", "pkg/trackzor-0.1.0.tar.gz", "pkg/trackzor-0.1.0/CHANGELOG", "pkg/trackzor-0.1.0/Manifest", "pkg/trackzor-0.1.0/README.rdoc", "pkg/trackzor-0.1.0/Rakefile", "pkg/trackzor-0.1.0/generators/trackzor_migration/templates/migration.rb", "pkg/trackzor-0.1.0/generators/trackzor_migration/trackzor_migration_generator.rb", "pkg/trackzor-0.1.0/init.rb", "pkg/trackzor-0.1.0/lib/trackzor.rb", "pkg/trackzor-0.1.0/trackzor.gemspec", "trackzor.gemspec"]
14
+ s.homepage = %q{http://bitbucket.org/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
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trackzor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Cornelius
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-08 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Track ATTR_updated_at and ATTR_updated_by with ease.
17
+ email: david.cornelius@bluefishwireless.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - CHANGELOG
24
+ - README.rdoc
25
+ - lib/trackzor.rb
26
+ files:
27
+ - CHANGELOG
28
+ - Manifest
29
+ - README.rdoc
30
+ - Rakefile
31
+ - generators/trackzor_migration/templates/migration.rb
32
+ - generators/trackzor_migration/trackzor_migration_generator.rb
33
+ - init.rb
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
+ - trackzor.gemspec
47
+ has_rdoc: true
48
+ homepage: http://bitbucket.org/corneldm/trackzor
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options:
53
+ - --line-numbers
54
+ - --inline-source
55
+ - --title
56
+ - Trackzor
57
+ - --main
58
+ - README.rdoc
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: "0"
66
+ version:
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: "1.2"
72
+ version:
73
+ requirements: []
74
+
75
+ rubyforge_project: trackzor
76
+ rubygems_version: 1.3.5
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: Track ATTR_updated_at and ATTR_updated_by with ease.
80
+ test_files: []
81
+