acts_as_activitable 0.0.2 → 0.0.3
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,9 @@
|
|
1
|
+
module ActivitiesHelper
|
2
|
+
def render_activity(activity)
|
3
|
+
begin
|
4
|
+
render :partial => "activities/#{activity.activitable_type.underscore}", :locals => {:activity => activity}
|
5
|
+
rescue ActionView::MissingTemplate => e
|
6
|
+
render :partial => "activities/default", :locals => {:activity => activity}
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<p>Whoops!!!!</p>
|
2
|
+
|
3
|
+
<p>Looks like you need to create a partial for <%= activity.activitable_type %>.</p>
|
4
|
+
|
5
|
+
<p>Just name it _<%= activity.activitable_type.underscore %>.html.erb and put it in views/activities.</p>
|
6
|
+
|
7
|
+
<p>Then you can format this data anyway you want!</p>
|
8
|
+
|
9
|
+
<pre><%= activity.inspect %></pre>
|
data/lib/acts_as_activitable.rb
CHANGED
@@ -1,61 +1,59 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'app', 'helpers', 'activities_helper')
|
2
|
+
|
3
|
+
ActionController::Base.helper(ActivitiesHelper)
|
4
|
+
|
1
5
|
module ActsAsActivitable
|
2
|
-
|
3
|
-
|
4
|
-
|
6
|
+
|
7
|
+
module Extensions
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.extend ClassMethods
|
11
|
+
end
|
5
12
|
|
6
|
-
|
7
|
-
|
8
|
-
|
13
|
+
module ClassMethods
|
14
|
+
def acts_as_activitable
|
15
|
+
cattr_accessor :exclude_from_activities
|
16
|
+
cattr_accessor :methods_for_activities
|
17
|
+
has_many :activities, :as => :activitable, :dependent => :destroy
|
9
18
|
|
10
|
-
|
19
|
+
after_create :create_activity
|
11
20
|
|
12
|
-
|
13
|
-
|
21
|
+
include ActsAsActivitable::Extensions::InstanceMethods
|
22
|
+
extend ActsAsActivitable::Extensions::SingletonMethods
|
23
|
+
end
|
14
24
|
end
|
15
|
-
end
|
16
25
|
|
17
|
-
|
18
|
-
|
19
|
-
@@exclude_from_activities
|
20
|
-
end
|
21
|
-
|
22
|
-
def exclude_from_activities(attribute_hash)
|
23
|
-
@@exclude_from_activities = attribute_hash
|
24
|
-
end
|
25
|
-
|
26
|
-
def methods_for_activities
|
27
|
-
@@methods_for_activities
|
28
|
-
end
|
29
|
-
|
30
|
-
def methods_for_activities(method_hash)
|
31
|
-
@@methods_for_activities = method_hash
|
26
|
+
module SingletonMethods
|
27
|
+
|
32
28
|
end
|
33
|
-
end
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
def activity_owner
|
38
|
-
user
|
39
|
-
end
|
30
|
+
module InstanceMethods
|
40
31
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
def to_activity_data
|
46
|
-
attrs = self.attributes.symbolize_keys
|
47
|
-
attrs.delete(:id)
|
48
|
-
self.class.exclude_from_activities.each do |attribute|
|
49
|
-
attrs.delete(attribute.to_sym)
|
32
|
+
def activity_owner
|
33
|
+
user
|
50
34
|
end
|
51
|
-
|
52
|
-
|
35
|
+
|
36
|
+
def create_activity
|
37
|
+
self.activities.create(:user => activity_owner, :data => self.to_activity_data)
|
53
38
|
end
|
39
|
+
|
40
|
+
def to_activity_data
|
41
|
+
attrs = self.attributes.symbolize_keys
|
42
|
+
attrs.delete(:id)
|
43
|
+
(self.class.exclude_from_activities||[]).each do |attribute|
|
44
|
+
attrs.delete(attribute.to_sym)
|
45
|
+
end
|
46
|
+
(self.class.methods_for_activities||[]).each do |method_name|
|
47
|
+
attrs[method_name.so_sym] = self.send(method_name.to_sym)
|
48
|
+
end
|
54
49
|
|
55
|
-
|
50
|
+
attrs
|
51
|
+
end
|
56
52
|
end
|
57
53
|
end
|
58
54
|
|
59
55
|
class Engine < ::Rails::Engine
|
60
56
|
end
|
61
57
|
end
|
58
|
+
|
59
|
+
ActiveRecord::Base.send(:include, ActsAsActivitable::Extensions)
|
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.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Gunner Technology, Cody Swann
|
@@ -28,7 +28,9 @@ files:
|
|
28
28
|
- Gemfile
|
29
29
|
- Rakefile
|
30
30
|
- acts_as_activitable.gemspec
|
31
|
+
- app/helpers/activities_helper.rb
|
31
32
|
- app/models/activity.rb
|
33
|
+
- app/views/activities/_default.html.erb
|
32
34
|
- lib/acts_as_activitable.rb
|
33
35
|
- lib/acts_as_activitable/version.rb
|
34
36
|
- lib/generators/acts_as_activitable/USAGE
|