activerecord-userstamp 3.0.0 → 3.0.1
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.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +5 -0
- data/README.md +3 -2
- data/lib/active_record/userstamp/stampable.rb +12 -10
- data/lib/active_record/userstamp/utilities.rb +22 -0
- data/lib/active_record/userstamp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a7867df9eb9d4eea12bdad4a66da1c5412e0593
|
4
|
+
data.tar.gz: b888a7d64f3f13306a2e0cf371775d3e99ba7aba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91875d1531de92434925a3408e7da73bd84b82a56490d4687409dd68c4169b33aa3e0e616a10f225829fd2257b42e61cfb1cc5a5b2d8957d4c645617bbec5555
|
7
|
+
data.tar.gz: d11f8898d2a39b569a76e9e124f78036a4dbcd2d46f396e1df94256d4861a31232df35b3d5e0cde13249d7a693d3ea1e32628eba13b4978d41f950fd7384da05
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
# Changelog
|
2
|
+
## 3.0.1 (11-7-2015)
|
3
|
+
* Joel Low - Only declare the creator/updater/deleter associations when the table has
|
4
|
+
the attribute columns. If the columns cannot be determined (e.g. if the
|
5
|
+
table has not been defined, such as during tests), then the model would
|
6
|
+
need to explicitly call `stampable`.
|
2
7
|
|
3
8
|
## 3.0.0 (10-7-2015)
|
4
9
|
* Joel Low - Remove `compatibility_mode`. Use the `creator_attribute`,
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ In addition to these, I have cherry picked ideas and changes from the following
|
|
27
27
|
- [konvenit](https://github.com/konvenit/userstamp)
|
28
28
|
|
29
29
|
Finally, this gem only supports Ruby 2.0 and above. Yes, you really should upgrade to a supported
|
30
|
-
version of Ruby.
|
30
|
+
version of Ruby. This gem is tested only on Rails 4.2; but it should work with Rails 4+.
|
31
31
|
|
32
32
|
## Features
|
33
33
|
### Soft-deletes
|
@@ -57,7 +57,8 @@ Do create a ticket if it is broken, with a pull-request if possible.
|
|
57
57
|
While examining the userstamp gem's network on Github, it was noticed that quite a few forks were
|
58
58
|
made to allow customisability in the name and type of the column with the database migration.
|
59
59
|
|
60
|
-
This gem now supports customised column names.
|
60
|
+
This gem now supports customised column names. See the [usage](#usage) section on the
|
61
|
+
configuration options supported.
|
61
62
|
|
62
63
|
### Saving before validation
|
63
64
|
This fork includes changes to perform model stamping before validation. This allows models to
|
@@ -68,21 +68,23 @@ module ActiveRecord::Userstamp::Stampable
|
|
68
68
|
|
69
69
|
# Defines the associations for Userstamp.
|
70
70
|
def add_userstamp_associations(options)
|
71
|
-
config = ActiveRecord::Userstamp.config
|
72
|
-
klass = stamper_class.try(:name)
|
73
|
-
relation_options = options.reverse_merge(class_name: klass)
|
74
|
-
|
75
71
|
ActiveRecord::Userstamp::Utilities.remove_association(self, :creator)
|
76
72
|
ActiveRecord::Userstamp::Utilities.remove_association(self, :updater)
|
77
73
|
ActiveRecord::Userstamp::Utilities.remove_association(self, :deleter)
|
78
74
|
|
79
|
-
|
80
|
-
|
75
|
+
associations = ActiveRecord::Userstamp::Utilities.available_association_columns(self)
|
76
|
+
return if associations.nil?
|
81
77
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
78
|
+
config = ActiveRecord::Userstamp.config
|
79
|
+
klass = stamper_class.try(:name)
|
80
|
+
relation_options = options.reverse_merge(class_name: klass)
|
81
|
+
|
82
|
+
belongs_to :creator, relation_options.reverse_merge(foreign_key: config.creator_attribute) if
|
83
|
+
associations.first
|
84
|
+
belongs_to :updater, relation_options.reverse_merge(foreign_key: config.updater_attribute) if
|
85
|
+
associations.second
|
86
|
+
belongs_to :deleter, relation_options.reverse_merge(foreign_key: config.deleter_attribute) if
|
87
|
+
associations.third
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
@@ -1,4 +1,9 @@
|
|
1
1
|
module ActiveRecord::Userstamp::Utilities
|
2
|
+
# Removes the association methods from the model.
|
3
|
+
#
|
4
|
+
# @param [Class] model The model to remove methods from.
|
5
|
+
# @param [Symbol] association The name of the association to remove.
|
6
|
+
# @return [void]
|
2
7
|
def self.remove_association(model, association)
|
3
8
|
methods = [
|
4
9
|
association,
|
@@ -14,5 +19,22 @@ module ActiveRecord::Userstamp::Utilities
|
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
22
|
+
|
23
|
+
# Obtains the creator/updater/deleter columns which are present in the model.
|
24
|
+
#
|
25
|
+
# @param [Class] model The model to query.
|
26
|
+
# @return [nil|Array<(bool, bool, bool)>] Nil if the model does not have a table defined.
|
27
|
+
# Otherwise, a tuple of booleans indicating the presence of the created, updated, and deleted
|
28
|
+
# columns.
|
29
|
+
def self.available_association_columns(model)
|
30
|
+
columns = Set[*model.column_names]
|
31
|
+
config = ActiveRecord::Userstamp.config
|
32
|
+
|
33
|
+
[config.creator_attribute.present? && columns.include?(config.creator_attribute.to_s),
|
34
|
+
config.updater_attribute.present? && columns.include?(config.updater_attribute.to_s),
|
35
|
+
config.deleter_attribute.present? && columns.include?(config.deleter_attribute.to_s)]
|
36
|
+
rescue ActiveRecord::StatementInvalid => _
|
37
|
+
nil
|
38
|
+
end
|
17
39
|
end
|
18
40
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-userstamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Low
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|