acts_as_feedable 1.0.0 → 1.1.0

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 116380fff364f58a7d7678b357567ba848dd8907
4
+ data.tar.gz: df7304ee85e6e67ee2f885f286303dceb4946c1b
5
+ SHA512:
6
+ metadata.gz: cbc51c0326344b1fceb393f2d1575cf88fc3ec5bca20cf1cd75f58958bf9923779d65a0c8d6c9bed1018cb97782181380a773a0b0b1c61ae483706474f7a48b9
7
+ data.tar.gz: 4c5cd6c9380dd5907fd292c3ed6daaba159db8cbb77427548ae7af9f5d5e6837d8082e1819f46d697529397e477232765e1db821eb79fec2066f62e2da4e53ac
@@ -41,7 +41,7 @@ When a feedable is deleted, one of three things happen:
41
41
 
42
42
  If the feedable is not being aggregated, there are two options:
43
43
  * We simply delete all related feeds to avoid problems that would occur because feed permissions are proxies of the destroyed object.
44
- * If the +keep_feeds_when_destroyed+ flag is set, we can add a destruction feed and inherit permissions from the feed's scoping object instead.
44
+ * If a feed_initiator is set, we can add a destruction feed and inherit permissions from the feed's scoping object instead.
45
45
 
46
46
  == Assumptions
47
47
 
@@ -4,9 +4,9 @@ class Feed < ActiveRecord::Base
4
4
  belongs_to :feedable, :polymorphic => true
5
5
  belongs_to :scoping_object, :polymorphic => true
6
6
 
7
- has_many :feed_aggregated_components, :dependent => :destroy, :order => 'feed_aggregated_components.updated_at DESC'
7
+ has_many :feed_aggregated_components, lambda { order 'feed_aggregated_components.updated_at DESC' }, :dependent => :destroy
8
8
 
9
- default_scope order('feeds.updated_at DESC')
9
+ default_scope lambda { order('feeds.updated_at DESC') }
10
10
 
11
11
  # Used to group feeds by the day they occurred
12
12
  def date
@@ -3,7 +3,6 @@ module Feedable #:nodoc:
3
3
  module ActMethod
4
4
  # Configuration options are:
5
5
  #
6
- # * +keep_feeds_when_destroyed+ - specifies whether to keep the feeds when a feedable is destroyed. This should only be done if the feedable is public or is scoped to another feedable.
7
6
  # * +target_name+ - specifies how to get the name of the target (used by the view to store the name of the primary object the feed links to). (default is nil)
8
7
  # * +scoping_object?+ - Boolean - If true, this object will become the scoping object for all feedables descending from it. eg. a Project is a scoping object for all discussions, comments, and writeboards within the project.
9
8
  # * +parent+ - Specifies the code to execute to traverse up the feedable chain in search of any scoping objects
@@ -26,9 +25,7 @@ module Feedable #:nodoc:
26
25
  include InstanceMethods unless included_modules.include?(InstanceMethods)
27
26
 
28
27
  # Sanity Check
29
- options.assert_valid_keys(:scoping_object?, :parent, :keep_feeds_when_destroyed, :target_name, :delegate, :aggregate)
30
-
31
- raise 'target_name option must be set if the keep_feeds_when_destroyed option is used' if options.key?(:keep_feeds_when_destroyed) && !options.key?(:target_name)
28
+ options.assert_valid_keys(:scoping_object?, :parent, :target_name, :delegate, :aggregate)
32
29
 
33
30
  options[:delegate].assert_valid_keys(:actions, :references) if options[:delegate].present?
34
31
  raise 'actions option must be set if the delegate option is used' if options[:delegate].is_a?(Hash) && options[:delegate][:actions].blank?
@@ -38,15 +35,11 @@ module Feedable #:nodoc:
38
35
  raise 'action option must be set if the aggregate option is used' if options[:aggregate].is_a?(Hash) && options[:aggregate][:action].blank?
39
36
  raise 'references option must be set if the aggregate option is used' if options[:aggregate].is_a?(Hash) && options[:aggregate][:references].blank?
40
37
 
41
- options.reverse_merge!(:keep_feeds_when_destroyed => false, :delegate => {}, :aggregate => {})
38
+ options.reverse_merge!(:delegate => {}, :aggregate => {})
42
39
 
43
40
  self.feed_options = options
44
41
 
45
42
  class_eval <<-EOV
46
-
47
- def keep_feeds_when_destroyed?
48
- #{options[:keep_feeds_when_destroyed]}
49
- end
50
43
 
51
44
  def feedable
52
45
  if delegating?
@@ -93,8 +86,8 @@ module Feedable #:nodoc:
93
86
  def self.extended(base)
94
87
  base.after_create :add_created_feed
95
88
  base.after_update :add_updated_feed
96
- base.before_destroy :setup_destroyed_feed_if_keeping_feeds
97
- base.after_destroy :add_destroyed_feed, :destroy_scoped_feeds
89
+ base.before_destroy :add_destroyed_feed
90
+ base.after_destroy :destroy_scoped_feeds
98
91
 
99
92
  base.cattr_accessor :feed_options
100
93
  base.has_many :feeds, :as => :feedable
@@ -226,24 +219,23 @@ module Feedable #:nodoc:
226
219
 
227
220
  # Creates a feed about the deletion of the feedable.
228
221
  # If the feed isn't aggregated then it deletes all existing feeds related to that object.
222
+ #
223
+ # Note: Create the destroyed feed before the feedable is destroyed so it gets the correct permission mappings
229
224
  def add_destroyed_feed
230
225
  if aggregating?
231
226
  update_aggregate_feed(:removed) if feed_initiator_id
232
227
  elsif delegating?
233
228
  create_feed_with_defaults(:action => delegate_action_for('destroyed')) if feed_initiator_id
234
- elsif !keep_feeds_when_destroyed?
229
+ elsif feed_initiator_id
230
+ raise 'target_name option must be set when destroying with feed' unless self.class.feed_options.key?(:target_name)
231
+ create_feed_with_defaults(:action => 'destroyed')
232
+ else
235
233
  Feed.destroy_all(:feedable_type => self.class.to_s, :feedable_id => id)
236
234
  end
235
+
237
236
  clear_initiator
238
237
  end
239
238
 
240
- # Create the destroyed feed before the feedable is destroyed so it gets the correct permission mappings
241
- def setup_destroyed_feed_if_keeping_feeds
242
- if keep_feeds_when_destroyed? && feed_initiator_id
243
- create_feed_with_defaults(:action => 'destroyed')
244
- end
245
- end
246
-
247
239
  # Destroy all feeds which are scoped to the feedable.
248
240
  # This will prevent feeds from not rendering because the feedable has been destroyed.
249
241
  def destroy_scoped_feeds
@@ -25,12 +25,12 @@ module JoinableExtensions
25
25
 
26
26
  def self.extend_membership
27
27
  Membership.class_eval do
28
+ before_destroy :ensure_feed_creation
29
+
28
30
  acts_as_feedable :parent => 'joinable', :delegate => {:references => 'user', :actions => {:created => 'joined', :destroyed => 'left'}}
29
31
 
30
32
  private
31
33
 
32
- before_destroy :ensure_feed_creation
33
-
34
34
  def ensure_feed_creation
35
35
  with_feed(initiator) if initiator.present?
36
36
  end
@@ -39,6 +39,9 @@ module JoinableExtensions
39
39
 
40
40
  def self.extend_membership_invitation
41
41
  MembershipInvitation.class_eval do
42
+ before_create :ensure_feed_creation
43
+ before_destroy :ensure_feed_creation
44
+
42
45
  acts_as_feedable :parent => 'joinable', :delegate => {:references => 'user', :actions => {:created => 'invited', :destroyed => 'cancelled_invite'}}
43
46
 
44
47
  attr_accessor :no_default_feed
@@ -55,9 +58,6 @@ module JoinableExtensions
55
58
  destroy_with_feed(user)
56
59
  end
57
60
 
58
- before_create :ensure_feed_creation
59
- before_destroy :ensure_feed_creation
60
-
61
61
  # Don't create a destroyed feed if the user is accepting a membership invitation or a membership request exists for this User.
62
62
  # In that case, a membership was created, and this invitation should be 'invisible' to the Users and the UI. Thus no feeds should be created.
63
63
  def ensure_feed_creation
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_feedable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ryan Wallace
@@ -10,8 +9,22 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-04-30 00:00:00.000000000 Z
14
- dependencies: []
12
+ date: 2013-08-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '4.0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '4.0'
15
28
  description: Allows objects to create feeds which describe them. These feeds can then
16
29
  be used in a "Facebook-style" News Feed.
17
30
  email: technical@rrnpilot.org
@@ -27,26 +40,25 @@ files:
27
40
  - README.rdoc
28
41
  homepage: http://github.com/rrn/acts_as_feedable
29
42
  licenses: []
43
+ metadata: {}
30
44
  post_install_message:
31
45
  rdoc_options: []
32
46
  require_paths:
33
47
  - lib
34
48
  required_ruby_version: !ruby/object:Gem::Requirement
35
- none: false
36
49
  requirements:
37
- - - ! '>='
50
+ - - '>='
38
51
  - !ruby/object:Gem::Version
39
52
  version: '0'
40
53
  required_rubygems_version: !ruby/object:Gem::Requirement
41
- none: false
42
54
  requirements:
43
- - - ! '>='
55
+ - - '>='
44
56
  - !ruby/object:Gem::Version
45
57
  version: '0'
46
58
  requirements: []
47
59
  rubyforge_project:
48
- rubygems_version: 1.8.25
60
+ rubygems_version: 2.0.5
49
61
  signing_key:
50
- specification_version: 3
62
+ specification_version: 4
51
63
  summary: Allows objects to create feeds which describe them
52
64
  test_files: []