activerecord-custom_timestamps 0.1.1 → 0.2.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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OWY1Njc3YWI5ZGRiN2ZkMjRjZjBkMTNhMTNkZWM1NzgzMjRkOWEyOA==
5
+ data.tar.gz: !binary |-
6
+ NGRjOGI2OTAwNDdhMjdlOTlmZmU5OTc2MTA0NDEzZjBmYWNkNzE4OQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZTkzMzYyZTE1ODYyMmE0Y2QwODZiZjc1NWNlNWE1ZjNhZmJhYWIwYmY4MGNi
10
+ NzRhZGNmNDg0NTJhM2VmODk3ODU3MGE1NjU0ZWIyNWQ5YTYzYjNjZTU1MmNh
11
+ ZjBiNWZhZjEyNmQ4N2ZhODU0ZGVlNTlkZTE4MmUwNDFiODJlZWE=
12
+ data.tar.gz: !binary |-
13
+ YjRiYzJmZGU5NWE4YjE1ZWQxZTA0YjU1NWRiYTEzOTliZWQyMDhiYmY1Y2Ex
14
+ OGZiYzI2NGU5NjA3MGNiOGFlOTU3MzVjZjk0ZGNiODlhNWQyNDhkYjAzMmVk
15
+ YzljMzViOGFjOWE5ODVkNDQ5MTlhZjYwNWEyNjllMjE1MzkwZTI=
data/README.md CHANGED
@@ -1,11 +1,12 @@
1
- Custom Timestamps for ActiveRecord 3.x/4.x and Rails 3.x/4.x
2
- =====
1
+ [![Build Status](https://secure.travis-ci.org/FineLinePrototyping/activerecord-custom_timestamps.png?branch=master)][travis] [![Gem Version](https://badge.fury.io/rb/activerecord-custom_timestamps.png)][badgefury]
3
2
 
4
- Sometimes you may need to use timestamp columns other than created_at/created_on and updated_at/updated_on, e.g. when you are using a legacy database. Custom Timestamps lets you define one or more additional columns to update just like Rails updates created_at/created_on and/or updated_at/updated_on.
3
+ ## Custom Timestamps for ActiveRecord 3.1+/4.x
4
+
5
+ Sometimes you may need to use timestamp columns other than created_at/created_on and updated_at/updated_on, e.g. when you are using a legacy database. Custom Timestamps lets you define one or more additional columns to update just like Rails updates created_at/created_on and/or updated_at/updated_on. In addition, it lets you define these columns in the model class and lets you define whether you want the application and/or model(s) to set the updated column(s) on creation.
5
6
 
6
7
  This does not change "timestamps" behavior in migrations. New models will continue to get updated_at/created_at or whatever you have designated, nor should it affect existing behavior in Rails (ActiveRecord::Timestamp) that looks for created_at/created_on and updated_at/updated_on and updates those on create/update.
7
8
 
8
- It uses the Rails/ActiveRecord 3.x-4.x self.record_timestamps to determine if it should update the date of the created_timestamp column(s) and should_record_timestamps? to determine if it should update the date of the updated_timestamp column(s) and it does these in the private create and update methods that then call super to execute the default ActiveRecord::Timestamp defined create and update methods.
9
+ It uses the Rails 3.1+-4.x/ActiveRecord 3.1+-4.x self.record_timestamps to determine if it should update the date of the created_timestamp column(s) and should_record_timestamps? to determine if it should update the date of the updated_timestamp column(s) and it does these in the private create and update methods that then call super to execute the default ActiveRecord::Timestamp defined create and update methods.
9
10
 
10
11
  ### Setup
11
12
 
@@ -13,10 +14,6 @@ In your ActiveRecord/Rails 3.1+ project, add this to your Gemfile:
13
14
 
14
15
  gem 'activerecord-custom_timestamps'
15
16
 
16
- For the development version:
17
-
18
- gem 'activerecord-custom_timestamps', :git => 'git://github.com/garysweaver/activerecord-custom_timestamps.git'
19
-
20
17
  Then run:
21
18
 
22
19
  bundle install
@@ -53,8 +50,26 @@ Please set this one to either true or false to avoid issues if defaults change l
53
50
 
54
51
  Just try to save and update an existing model that has the custom timestamp columns.
55
52
 
53
+ ### Using Without Rails
54
+
55
+ If using Rails, the appropriate module will be included into ActiveRecord::Base for Rails 3 or 4 (the method names changed in 4).
56
+
57
+ If you aren't using Rails, you'll want to include the appropriate module in your model or base model, e.g.
58
+
59
+ ```ruby
60
+ include ActiveRecord::VERSION::MAJOR > 3 ? ::CustomTimestamps::Model : ::CustomTimestamps::Rails3Model
61
+ ```
62
+
63
+ ### Authors
64
+
65
+ This app was written by [FineLine Prototyping, Inc.](http://www.finelineprototyping.com) by the following contributors:
66
+ * Gary Weaver (https://github.com/garysweaver)
67
+
56
68
  ### License
57
69
 
58
- Copyright (c) 2012 Gary S. Weaver, released under the [MIT license][lic].
70
+ Copyright (c) 2013 FineLine Prototyping, Inc., released under the [MIT license][lic].
71
+
72
+ [lic]: http://github.com/FineLinePrototyping/activerecord-custom_timestamps/blob/master/LICENSE
73
+ [travis]: http://travis-ci.org/FineLinePrototyping/activerecord-custom_timestamps
74
+ [badgefury]: http://badge.fury.io/rb/activerecord-custom_timestamps
59
75
 
60
- [lic]: http://github.com/garysweaver/activerecord-custom_timestamps/blob/master/LICENSE
data/Rakefile CHANGED
@@ -1,10 +1,15 @@
1
- require 'rake/testtask'
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'appraisal'
2
4
 
3
- Rake::TestTask.new(:test) do |t|
4
- t.libs << 'test'
5
- t.test_files = FileList['test/**/*_test.rb']
6
- t.verbose = true
5
+ task :default do |t|
6
+ if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
7
+ load 'test/custom_timestamps_test.rb'
8
+ else
9
+ exec 'bundle install && bundle exec rake appraise'
10
+ end
7
11
  end
8
12
 
9
- desc "Run tests"
10
- task :default => :test
13
+ task :appraise => ['appraisal:install'] do |t|
14
+ exec 'bundle install && bundle exec rake appraisal'
15
+ end
@@ -1,4 +1,5 @@
1
1
  require 'activerecord-custom_timestamps/version'
2
2
  require 'activerecord-custom_timestamps/config'
3
3
  require 'activerecord-custom_timestamps/model'
4
+ require 'activerecord-custom_timestamps/rails3_model'
4
5
  require 'activerecord-custom_timestamps/railtie' if defined?(Rails)
@@ -1,7 +1,9 @@
1
1
  module CustomTimestamps
2
2
  class << self
3
3
  attr_accessor :update_custom_updated_timestamp_on_create
4
- alias_method :update_custom_updated_timestamp_on_create?, :update_custom_updated_timestamp_on_create
4
+ def update_custom_updated_timestamp_on_create?
5
+ !!update_custom_updated_timestamp_on_create
6
+ end
5
7
  end
6
8
  end
7
9
 
@@ -13,39 +13,38 @@ module CustomTimestamps
13
13
 
14
14
  private
15
15
 
16
- def create
16
+ def create_record
17
17
  if self.record_timestamps
18
18
  current_time = current_time_from_proper_timezone
19
- if self.created_timestamp
20
- Array.wrap(self.created_timestamp).each do |column|
21
- if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
22
- write_attribute(column.to_s, current_time)
23
- end
19
+
20
+ Array.wrap(self.created_timestamp).each do |column|
21
+ if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
22
+ write_attribute(column.to_s, current_time)
24
23
  end
25
24
  end
26
25
 
27
- if self.updated_timestamp && self.update_custom_updated_timestamp_on_create?
26
+ if self.update_custom_updated_timestamp_on_create
28
27
  Array.wrap(self.updated_timestamp).each do |column|
29
- if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
30
- write_attribute(column.to_s, current_time)
31
- end
28
+ column = column.to_s
29
+ next if attribute_changed?(column)
30
+ write_attribute(column, current_time)
32
31
  end
33
32
  end
34
33
  end
35
-
34
+
36
35
  super
37
36
  end
38
37
 
39
- def update(*args)
40
- if self.updated_timestamp && should_record_timestamps?
38
+ def update_record(*args)
39
+ if should_record_timestamps?
41
40
  current_time = current_time_from_proper_timezone
41
+
42
42
  Array.wrap(self.updated_timestamp).each do |column|
43
43
  column = column.to_s
44
44
  next if attribute_changed?(column)
45
45
  write_attribute(column, current_time)
46
46
  end
47
47
  end
48
-
49
48
  super
50
49
  end
51
50
  end
@@ -0,0 +1,51 @@
1
+ require 'activerecord-custom_timestamps/config'
2
+
3
+ module CustomTimestamps
4
+ module Rails3Model
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ class_attribute :created_timestamp, instance_writer: false
9
+ class_attribute :updated_timestamp, instance_writer: false
10
+ class_attribute :update_custom_updated_timestamp_on_create, instance_writer: false
11
+ self.update_custom_updated_timestamp_on_create = CustomTimestamps.update_custom_updated_timestamp_on_create?
12
+ end
13
+
14
+ private
15
+
16
+ def create
17
+ if self.record_timestamps
18
+ current_time = current_time_from_proper_timezone
19
+
20
+ Array.wrap(self.created_timestamp).each do |column|
21
+ if respond_to?(column) && respond_to?("#{column}=") && self.send(column).nil?
22
+ write_attribute(column.to_s, current_time)
23
+ end
24
+ end
25
+
26
+ if self.update_custom_updated_timestamp_on_create
27
+ Array.wrap(self.updated_timestamp).each do |column|
28
+ column = column.to_s
29
+ next if attribute_changed?(column)
30
+ write_attribute(column, current_time)
31
+ end
32
+ end
33
+ end
34
+
35
+ super
36
+ end
37
+
38
+ def update(*args)
39
+ if should_record_timestamps?
40
+ current_time = current_time_from_proper_timezone
41
+
42
+ Array.wrap(self.updated_timestamp).each do |column|
43
+ column = column.to_s
44
+ next if attribute_changed?(column)
45
+ write_attribute(column, current_time)
46
+ end
47
+ end
48
+ super
49
+ end
50
+ end
51
+ end
@@ -4,7 +4,7 @@ module CustomTimestamps
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "custom_timestamps.active_record" do
6
6
  ActiveSupport.on_load(:active_record) do
7
- include CustomTimestamps::Model
7
+ include Rails::VERSION::MAJOR > 3 ? ::CustomTimestamps::Model : ::CustomTimestamps::Rails3Model
8
8
  end
9
9
  end
10
10
  end
@@ -1,3 +1,3 @@
1
1
  module CustomTimestamps
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,34 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-custom_timestamps
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.1.1
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Gary S. Weaver
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-09-27 00:00:00.000000000 Z
11
+ date: 2013-08-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activerecord
16
- version_requirements: !ruby/object:Gem::Requirement
15
+ requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
17
  - - ! '>='
19
18
  - !ruby/object:Gem::Version
20
- version: !binary |-
21
- MA==
22
- none: false
23
- requirement: !ruby/object:Gem::Requirement
19
+ version: '3.1'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
24
26
  requirements:
25
27
  - - ! '>='
26
28
  - !ruby/object:Gem::Version
27
- version: !binary |-
28
- MA==
29
- none: false
30
- prerelease: false
31
- type: :runtime
29
+ version: '3.1'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
32
33
  description: Allows sets of custom timestamps for all or some models.
33
34
  email:
34
35
  - garysweaver@gmail.com
@@ -36,22 +37,19 @@ executables: []
36
37
  extensions: []
37
38
  extra_rdoc_files: []
38
39
  files:
39
- - !binary |-
40
- bGliL2FjdGl2ZXJlY29yZC1jdXN0b21fdGltZXN0YW1wcy5yYg==
41
- - !binary |-
42
- bGliL2FjdGl2ZXJlY29yZC1jdXN0b21fdGltZXN0YW1wcy9jb25maWcucmI=
43
- - !binary |-
44
- bGliL2FjdGl2ZXJlY29yZC1jdXN0b21fdGltZXN0YW1wcy9tb2RlbC5yYg==
45
- - !binary |-
46
- bGliL2FjdGl2ZXJlY29yZC1jdXN0b21fdGltZXN0YW1wcy9yYWlsdGllLnJi
47
- - !binary |-
48
- bGliL2FjdGl2ZXJlY29yZC1jdXN0b21fdGltZXN0YW1wcy92ZXJzaW9uLnJi
40
+ - lib/activerecord-custom_timestamps/config.rb
41
+ - lib/activerecord-custom_timestamps/model.rb
42
+ - lib/activerecord-custom_timestamps/rails3_model.rb
43
+ - lib/activerecord-custom_timestamps/railtie.rb
44
+ - lib/activerecord-custom_timestamps/version.rb
45
+ - lib/activerecord-custom_timestamps.rb
49
46
  - Rakefile
50
47
  - README.md
51
- homepage: https://github.com/garysweaver/activerecord-custom_timestamps
48
+ homepage: https://github.com/FineLinePrototyping/activerecord-custom_timestamps
52
49
  licenses:
53
50
  - MIT
54
- post_install_message:
51
+ metadata: {}
52
+ post_install_message:
55
53
  rdoc_options: []
56
54
  require_paths:
57
55
  - lib
@@ -59,21 +57,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
59
57
  requirements:
60
58
  - - ! '>='
61
59
  - !ruby/object:Gem::Version
62
- version: !binary |-
63
- MA==
64
- none: false
60
+ version: '0'
65
61
  required_rubygems_version: !ruby/object:Gem::Requirement
66
62
  requirements:
67
63
  - - ! '>='
68
64
  - !ruby/object:Gem::Version
69
- version: !binary |-
70
- MA==
71
- none: false
65
+ version: '0'
72
66
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 1.8.24
75
- signing_key:
76
- specification_version: 3
67
+ rubyforge_project:
68
+ rubygems_version: 2.0.6
69
+ signing_key:
70
+ specification_version: 4
77
71
  summary: Custom Timestamps for ActiveRecord 3.x/4.x.
78
72
  test_files: []
79
- ...