change_log 0.0.3 → 0.0.4
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.textile +82 -0
- data/lib/change_log/version.rb +1 -1
- metadata +4 -4
- data/.gitignore +0 -4
data/README.textile
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
h1. Change Log
|
2
|
+
|
3
|
+
A gem to keep all maintenances in database
|
4
|
+
|
5
|
+
|
6
|
+
h2. Install Change Log Gem
|
7
|
+
|
8
|
+
1. by command:
|
9
|
+
<pre><code># gem install change_log</code></pre>
|
10
|
+
|
11
|
+
2. or by bundler
|
12
|
+
<pre><code># Gemfile in your application
|
13
|
+
gem 'change_log'
|
14
|
+
</code></pre>
|
15
|
+
|
16
|
+
Then:
|
17
|
+
<pre><code>bundle install</code></pre>
|
18
|
+
|
19
|
+
h2. Create a table to keep all maintenance logs
|
20
|
+
|
21
|
+
Generate a migration file
|
22
|
+
|
23
|
+
<pre><code>
|
24
|
+
class AddChangeLog < ActiveRecord::Migration
|
25
|
+
def self.up
|
26
|
+
create_table :change_logs do |t|
|
27
|
+
t.integer :version, :null=>false # store version of each change
|
28
|
+
t.string :record_id,:limit=>30 # store the actual record id
|
29
|
+
t.string :table_name, :limit=>60 # store the table name
|
30
|
+
t.string :attribute_name,:limit=>60 # store the column name
|
31
|
+
t.string :user, :limit=>20 # store the user who made the change
|
32
|
+
t.string :action, :limit=>6 # store the change action: create, read, update, delete
|
33
|
+
t.text :old_value # the value before change
|
34
|
+
t.text :new_value # value after change
|
35
|
+
t.string :field_type, :limit=>30 # the column type eg. date, text, varchar, int etc
|
36
|
+
t.timestamps
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.down
|
41
|
+
drop_table :change_logs
|
42
|
+
end
|
43
|
+
end
|
44
|
+
</code></pre>
|
45
|
+
|
46
|
+
Then:
|
47
|
+
<pre><code>rake db:migrate</code></pre>
|
48
|
+
|
49
|
+
h2. Use Change Log
|
50
|
+
|
51
|
+
1. Include change_log in environment.rb
|
52
|
+
<pre><code>require 'change_log'</code></pre>
|
53
|
+
|
54
|
+
2. Add current_user method in application_controller.rb
|
55
|
+
<pre><code>
|
56
|
+
# used by change log
|
57
|
+
def current_user
|
58
|
+
return session[:user] # replace this with your own code to tell change_log who is the current user
|
59
|
+
end
|
60
|
+
</code></pre>
|
61
|
+
|
62
|
+
3. Models
|
63
|
+
<pre><code>
|
64
|
+
enable_change_log :ignore=>[:updated_at]
|
65
|
+
</code></pre>
|
66
|
+
|
67
|
+
Put any columns you do not want to keep in the change log table in :ignore option.
|
68
|
+
eg. the password hash
|
69
|
+
|
70
|
+
|
71
|
+
h2. Testing
|
72
|
+
|
73
|
+
TODO
|
74
|
+
|
75
|
+
|
76
|
+
h3. Author
|
77
|
+
----
|
78
|
+
|
79
|
+
Peter Zhang at NCS New Zealand.
|
80
|
+
Email: peterz@ncs.co.nz
|
81
|
+
|
82
|
+
Copyright (c) 2011 Peter Zhang, released under the MIT license
|
data/lib/change_log/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: change_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Peter Zhang
|
@@ -42,9 +42,9 @@ extensions: []
|
|
42
42
|
extra_rdoc_files: []
|
43
43
|
|
44
44
|
files:
|
45
|
-
- .gitignore
|
46
45
|
- Gemfile
|
47
46
|
- MIT-LICENSE
|
47
|
+
- README.textile
|
48
48
|
- Rakefile
|
49
49
|
- change_log.gemspec
|
50
50
|
- lib/change_log.rb
|
data/.gitignore
DELETED