acts_as_activitable 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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>
@@ -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
- def self.included(base)
3
- base.extend ClassMethods
4
- end
6
+
7
+ module Extensions
8
+
9
+ def self.included(base)
10
+ base.extend ClassMethods
11
+ end
5
12
 
6
- module ClassMethods
7
- def acts_as_activitable
8
- has_many :activities, :as => :activitable, :dependent => :destroy
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
- after_create :create_activity
19
+ after_create :create_activity
11
20
 
12
- include ActsAsActivitable::InstanceMethods
13
- extend ActsAsActivitable::SingletonMethods
21
+ include ActsAsActivitable::Extensions::InstanceMethods
22
+ extend ActsAsActivitable::Extensions::SingletonMethods
23
+ end
14
24
  end
15
- end
16
25
 
17
- module SingletonMethods
18
- def exclude_from_activities
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
- module InstanceMethods
36
-
37
- def activity_owner
38
- user
39
- end
30
+ module InstanceMethods
40
31
 
41
- def create_activity
42
- self.activities.create(:user => activity_owner, :data => self.to_activity_data)
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
- self.class.methods_for_activities.each do |method_name|
52
- attrs[method_name.so_sym] = self.send(method_name.to_sym)
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
- attrs
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)
@@ -1,3 +1,3 @@
1
1
  module ActsAsActivitable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  class CreateActivities < ActiveRecord::Migration
2
2
  def self.up
3
3
  create_table :activities do |t|
4
- t.references :activitiable, :polymorphic => true
4
+ t.references :activitable, :polymorphic => true
5
5
  t.references :user
6
6
  t.text :data
7
7
  t.timestamps
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.2
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