activerecord-custom_timestamps 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
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=
2
+ SHA1:
3
+ metadata.gz: d7e696d572ca7d365e18040ec0720c11c8d19173
4
+ data.tar.gz: 0565454f72ab635e96965bd06e8d8dd9415c132b
5
+ SHA512:
6
+ metadata.gz: 63bd9a2c6e68c8d826cb9f0013d5dc160fb387432ef47f73ec2400f566ae22ccf50f5c836c05f3ba6a8e1e8c8dd364366ed94d8b1a10b528428db3acaceab756
7
+ data.tar.gz: be9b2fe5f08421bc2e3ec97a495f466bf05247fd80971a4a1d004a4e8a4586d861b1df1b281f938b40b8e8ee156ddd5b5a51d842cfe92b70f6399b9f196a0a3f
data/README.md CHANGED
@@ -52,22 +52,33 @@ Just try to save and update an existing model that has the custom timestamp colu
52
52
 
53
53
  ### Using Without Rails
54
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).
55
+ If using Rails, the appropriate module will be included into ActiveRecord::Base for Rails 3 or 4 (the method names changed in 4, then again in 4.2).
56
56
 
57
57
  If you aren't using Rails, you'll want to include the appropriate module in your model or base model, e.g.
58
58
 
59
+ Rails 4.2+:
59
60
  ```ruby
60
- include ActiveRecord::VERSION::MAJOR > 3 ? ::CustomTimestamps::Model : ::CustomTimestamps::Rails3Model
61
+ include ::CustomTimestamps::Model
62
+ ```
63
+
64
+ Rails 4.0-4.1.x:
65
+ ```ruby
66
+ include ::CustomTimestamps::EarlyRails4Model
67
+ ```
68
+
69
+ Rails 3.1.x+ but < 4:
70
+ ```ruby
71
+ include ::CustomTimestamps::Rails3Model
61
72
  ```
62
73
 
63
74
  ### Authors
64
75
 
65
- This app was written by [FineLine Prototyping, Inc.](http://www.finelineprototyping.com) by the following contributors:
76
+ This was written by [FineLine Prototyping, Inc.](http://www.finelineprototyping.com) by the following contributors:
66
77
  * Gary Weaver (https://github.com/garysweaver)
67
78
 
68
79
  ### License
69
80
 
70
- Copyright (c) 2013 FineLine Prototyping, Inc., released under the [MIT license][lic].
81
+ Copyright (c) 2013-2015 FineLine Prototyping, Inc., released under the [MIT license][lic].
71
82
 
72
83
  [lic]: http://github.com/FineLinePrototyping/activerecord-custom_timestamps/blob/master/LICENSE
73
84
  [travis]: http://travis-ci.org/FineLinePrototyping/activerecord-custom_timestamps
data/Rakefile CHANGED
@@ -2,14 +2,15 @@ require 'bundler/setup'
2
2
  require 'bundler/gem_tasks'
3
3
  require 'appraisal'
4
4
 
5
- task :default do |t|
5
+ # Override the default task
6
+ task :default => [] # Just in case it hasn't already been set
7
+ Rake::Task[:default].clear
8
+ task :default => :appraise
9
+
10
+ task :appraise do |t|
6
11
  if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
7
12
  load 'test/custom_timestamps_test.rb'
8
13
  else
9
- exec 'bundle install && bundle exec rake appraise'
14
+ exec 'appraisal install && rake appraisal'
10
15
  end
11
16
  end
12
-
13
- task :appraise => ['appraisal:install'] do |t|
14
- exec 'bundle install && bundle exec rake appraisal'
15
- end
@@ -0,0 +1,52 @@
1
+ require 'activerecord-custom_timestamps/config'
2
+
3
+ module CustomTimestamps
4
+ module EarlyRails4Model
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_record
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_record(*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
+
51
+ end
52
+ end
@@ -13,7 +13,7 @@ module CustomTimestamps
13
13
 
14
14
  private
15
15
 
16
- def create_record
16
+ def _create_record
17
17
  if self.record_timestamps
18
18
  current_time = current_time_from_proper_timezone
19
19
 
@@ -35,8 +35,8 @@ module CustomTimestamps
35
35
  super
36
36
  end
37
37
 
38
- def update_record(*args)
39
- if should_record_timestamps?
38
+ def _update_record(*args, touch: true, **options)
39
+ if touch && should_record_timestamps?
40
40
  current_time = current_time_from_proper_timezone
41
41
 
42
42
  Array.wrap(self.updated_timestamp).each do |column|
@@ -45,7 +45,8 @@ module CustomTimestamps
45
45
  write_attribute(column, current_time)
46
46
  end
47
47
  end
48
- super
48
+ super(*args, touch, **options)
49
49
  end
50
+
50
51
  end
51
52
  end
@@ -4,7 +4,15 @@ 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 Rails::VERSION::MAJOR > 3 ? ::CustomTimestamps::Model : ::CustomTimestamps::Rails3Model
7
+ if Rails::VERSION::MAJOR == 4
8
+ if Rails::VERSION::MINOR < 2
9
+ include ::CustomTimestamps::EarlyRails4Model
10
+ else
11
+ include ::CustomTimestamps::Model
12
+ end
13
+ elsif Rails::VERSION::MAJOR == 3
14
+ include ::CustomTimestamps::Rails3Model
15
+ end
8
16
  end
9
17
  end
10
18
  end
@@ -1,3 +1,3 @@
1
1
  module CustomTimestamps
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,33 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-custom_timestamps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary S. Weaver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-02 00:00:00.000000000 Z
11
+ date: 2015-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - ! '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.1'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5'
33
33
  description: Allows sets of custom timestamps for all or some models.
@@ -37,14 +37,15 @@ executables: []
37
37
  extensions: []
38
38
  extra_rdoc_files: []
39
39
  files:
40
+ - README.md
41
+ - Rakefile
42
+ - lib/activerecord-custom_timestamps.rb
40
43
  - lib/activerecord-custom_timestamps/config.rb
44
+ - lib/activerecord-custom_timestamps/early_rails4_model.rb
41
45
  - lib/activerecord-custom_timestamps/model.rb
42
46
  - lib/activerecord-custom_timestamps/rails3_model.rb
43
47
  - lib/activerecord-custom_timestamps/railtie.rb
44
48
  - lib/activerecord-custom_timestamps/version.rb
45
- - lib/activerecord-custom_timestamps.rb
46
- - Rakefile
47
- - README.md
48
49
  homepage: https://github.com/FineLinePrototyping/activerecord-custom_timestamps
49
50
  licenses:
50
51
  - MIT
@@ -55,17 +56,17 @@ require_paths:
55
56
  - lib
56
57
  required_ruby_version: !ruby/object:Gem::Requirement
57
58
  requirements:
58
- - - ! '>='
59
+ - - ">="
59
60
  - !ruby/object:Gem::Version
60
61
  version: '0'
61
62
  required_rubygems_version: !ruby/object:Gem::Requirement
62
63
  requirements:
63
- - - ! '>='
64
+ - - ">="
64
65
  - !ruby/object:Gem::Version
65
66
  version: '0'
66
67
  requirements: []
67
68
  rubyforge_project:
68
- rubygems_version: 2.0.6
69
+ rubygems_version: 2.4.5
69
70
  signing_key:
70
71
  specification_version: 4
71
72
  summary: Custom Timestamps for ActiveRecord 3.x/4.x.