created-and-updated-by 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/created-and-updated-by.gemspec +1 -1
- data/lib/created-and-updated-by.rb +12 -8
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module CreatedAndUpdatedBy
|
1
|
+
module CreatedAndUpdatedBy
|
2
2
|
class Stamper
|
3
3
|
cattr_accessor :stampable, :attribute
|
4
4
|
def self.attach(stamp_model = User, stamp_attribute = :current)
|
@@ -7,14 +7,18 @@ module CreatedAndUpdatedBy
|
|
7
7
|
ActiveRecord::Base.send(:include, CreatedAndUpdatedBy)
|
8
8
|
end
|
9
9
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def self.included(base)
|
11
|
+
base.class_eval do
|
12
|
+
send :include, InstanceMethods
|
13
|
+
before_validation :set_stamps
|
14
|
+
belongs_to :updated_by, :class_name => CreatedAndUpdatedBy::Stamper.stampable.name
|
15
|
+
belongs_to :created_by, :class_name => CreatedAndUpdatedBy::Stamper.stampable.name
|
13
16
|
end
|
14
|
-
|
15
|
-
|
17
|
+
end
|
18
|
+
module InstanceMethods
|
19
|
+
def stamper; CreatedAndUpdatedBy::Stamper.stampable.send(CreatedAndUpdatedBy::Stamper.attribute); end
|
16
20
|
def set_stamps
|
17
|
-
self.
|
21
|
+
self.created_by ||= self.updated_by = stamper if stamper && respond_to?(:created_by_id) && respond_to?(:updated_by_id)
|
18
22
|
end
|
19
|
-
end
|
23
|
+
end
|
20
24
|
end
|