acts_as_activitable 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/acts_as_activitable.rb +50 -13
- data/lib/acts_as_activitable/version.rb +1 -1
- metadata +2 -2
data/lib/acts_as_activitable.rb
CHANGED
@@ -12,11 +12,13 @@ module ActsAsActivitable
|
|
12
12
|
|
13
13
|
module ClassMethods
|
14
14
|
def acts_as_activitable
|
15
|
-
|
16
|
-
|
15
|
+
|
16
|
+
attr_accessor :skip_activity
|
17
17
|
has_many :activities, :as => :activitable, :dependent => :destroy
|
18
18
|
|
19
|
-
after_create :
|
19
|
+
after_create :create_create_activity
|
20
|
+
after_update :create_update_activity
|
21
|
+
after_destroy :create_destroy_activity
|
20
22
|
|
21
23
|
include ActsAsActivitable::Extensions::InstanceMethods
|
22
24
|
extend ActsAsActivitable::Extensions::SingletonMethods
|
@@ -24,7 +26,13 @@ module ActsAsActivitable
|
|
24
26
|
end
|
25
27
|
|
26
28
|
module SingletonMethods
|
29
|
+
def exclude_from_activities
|
30
|
+
[]
|
31
|
+
end
|
27
32
|
|
33
|
+
def methods_for_activities
|
34
|
+
[]
|
35
|
+
end
|
28
36
|
end
|
29
37
|
|
30
38
|
module InstanceMethods
|
@@ -32,21 +40,50 @@ module ActsAsActivitable
|
|
32
40
|
def activity_owner
|
33
41
|
user
|
34
42
|
end
|
43
|
+
|
44
|
+
def create_activity?(data)
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_create_activity
|
49
|
+
create_activity(:create)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_update_activity
|
53
|
+
create_activity(:update)
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_destroy_activity
|
57
|
+
create_activity(:destroy)
|
58
|
+
end
|
35
59
|
|
36
|
-
def create_activity
|
37
|
-
|
60
|
+
def create_activity(activity_action)
|
61
|
+
unless skip_activity
|
62
|
+
data = self.to_activity_data
|
63
|
+
|
64
|
+
if data
|
65
|
+
data.delete(:updated_at)
|
66
|
+
data.delete(:birth_date)
|
67
|
+
unless data.keys.empty? || !create_activity?(data)
|
68
|
+
data[:activity_action] = activity_action
|
69
|
+
self.activities.create(:user => activity_owner, :data => data) rescue nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
38
73
|
end
|
39
74
|
|
40
75
|
def to_activity_data
|
41
|
-
attrs =
|
42
|
-
|
43
|
-
|
44
|
-
attrs.delete(
|
45
|
-
|
46
|
-
|
47
|
-
|
76
|
+
attrs = nil
|
77
|
+
if self.changed?
|
78
|
+
attrs = self.changes.symbolize_keys
|
79
|
+
#attrs.delete(:id)
|
80
|
+
(self.class.exclude_from_activities||[]).each do |attribute|
|
81
|
+
attrs.delete(attribute.to_sym)
|
82
|
+
end
|
83
|
+
(self.class.methods_for_activities||[]).each do |method_name|
|
84
|
+
attrs[method_name.to_sym] = self.send(method_name.to_sym)
|
85
|
+
end
|
48
86
|
end
|
49
|
-
|
50
87
|
attrs
|
51
88
|
end
|
52
89
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: acts_as_activitable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gunner Technology, Cody Swann
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-14 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|