acts_as_notifiable 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module ActsAsNotifiable
2
- def acts_as_notifiable
3
- has_many :notifications, as: :notifiable, dependent: :destroy
2
+ def acts_as_notifiable(options={})
3
+ has_many :notifications, as: :notifiable, dependent: :delete_all
4
4
 
5
5
  after_create :create_notification
6
6
 
@@ -51,8 +51,19 @@ module ActsAsNotifiable
51
51
 
52
52
  # Callback method to create the notification
53
53
  def create_notification
54
- # Notification.create(user_id: self.user_id, notifiable_id: self.id, notifiable_type: self.class.to_s)
55
- Notification.find_or_create_by_user_id_and_notifiable_id_and_notifiable_type(self.user_id, self.id, self.class.to_s)
54
+ # if options[:polymorphic] == true
55
+ # t = create_polymorphic_sender
56
+ # Notification.send(t)
57
+ # else
58
+ Notification.find_or_create_by_user_id_and_notifiable_id_and_notifiable_type(self.user_id, self.id, self.class.to_s)
59
+ # end
60
+ end
61
+
62
+ def create_polymorphic_sender
63
+ type = ""
64
+ self.notifiable.attributes.each{|a| type = a[0] if a[0] =~ /ble_type/ }
65
+ type = self.notifiable.send(type)
66
+ "find_or_create_by_user_id_and_notifiable_id_and_notifiable_type_and"
56
67
  end
57
68
  end
58
69
  end
@@ -7,7 +7,7 @@ class Notification < ActiveRecord::Base
7
7
 
8
8
  # Associations
9
9
  belongs_to :notifiable, polymorphic: true
10
- belongs_to :user
10
+ belongs_to :user, counter_cache: true
11
11
 
12
12
  def as_json(options=nil)
13
13
  super(options || {
@@ -15,4 +15,4 @@ class Notification < ActiveRecord::Base
15
15
  })
16
16
  end
17
17
 
18
- end
18
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_notifiable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
43
  version: '0'
44
44
  requirements: []
45
45
  rubyforge_project:
46
- rubygems_version: 1.8.24
46
+ rubygems_version: 1.8.15
47
47
  signing_key:
48
48
  specification_version: 3
49
49
  summary: Manages notifiable objects