timestamped_column 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ Time-stamped Column
2
+ ===================
3
+
4
+ Records modified time for individual columns.
5
+
6
+ Usage (in a model)
7
+ ------------------
8
+
9
+ `timestamped_column :email_address`
10
+
11
+ Records the most recent modification time of `:email_address` to `:email_address_updated_at` (defaults to `name_updated_at`)
12
+
13
+
14
+ `timestamped_column :email_address, :column => :email_address_changed_at`
15
+
16
+ Records the most recent modification time of `:email_address` to `:email_address_changed_at`
@@ -0,0 +1,34 @@
1
+ module TimestampedColumn::ActiveRecord
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ before_save :update_timestamped_column_times
6
+ cattr_accessor :timestamped_columns
7
+ end
8
+
9
+ module ClassMethods
10
+ def timestamped_column(column, opts={})
11
+ timestamp_column = opts[:column] || "#{column}_updated_at"
12
+
13
+ self.timestamped_columns ||= {}
14
+ self.timestamped_columns[column] = timestamp_column
15
+ end
16
+ end
17
+
18
+ module InstanceMethods
19
+ private
20
+ def update_timestamped_column_times
21
+ if self.timestamped_columns && changes.any?
22
+ self.timestamped_columns.each do |column, timestamp_column|
23
+ if changes[column.to_s]
24
+ send "#{timestamp_column}=", Time.zone.now
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ class ActiveRecord::Base
33
+ include TimestampedColumn::ActiveRecord
34
+ end
@@ -0,0 +1,3 @@
1
+ module TimestampedColumn
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'active_support/concern'
2
+ require 'timestamped_column/active_record'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: timestamped_column
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - James Brooks
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70285269272880 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70285269272880
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70285269271000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70285269271000
36
+ description: Records modified time for individual columns.
37
+ email:
38
+ - james@jamesbrooks.net
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - lib/timestamped_column/active_record.rb
44
+ - lib/timestamped_column/version.rb
45
+ - lib/timestamped_column.rb
46
+ - MIT-LICENSE
47
+ - README.md
48
+ homepage: https://github.com/JamesBrooks/timestamped_column
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.6
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Records modified time for individual columns.
72
+ test_files: []