Module: JoinableExtensions
- Defined in:
- lib/feedable/joinable_extensions.rb
Class Method Summary collapse
- .add ⇒ Object
- .extend_membership ⇒ Object
- .extend_membership_invitation ⇒ Object
- .extend_membership_request ⇒ Object
Class Method Details
.add ⇒ Object
20 21 22 23 24 |
# File 'lib/feedable/joinable_extensions.rb', line 20 def self.add extend_membership extend_membership_invitation extend_membership_request end |
.extend_membership ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/feedable/joinable_extensions.rb', line 26 def self.extend_membership Membership.class_eval do before_destroy :ensure_feed_creation acts_as_feedable :parent => 'joinable', :delegate => {:references => 'user', :actions => {:created => 'joined', :destroyed => 'left'}} private def ensure_feed_creation with_feed(initiator) if initiator.present? end end end |
.extend_membership_invitation ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/feedable/joinable_extensions.rb', line 40 def self.extend_membership_invitation MembershipInvitation.class_eval do before_create :ensure_feed_creation before_destroy :ensure_feed_creation acts_as_feedable :parent => 'joinable', :delegate => {:references => 'user', :actions => {:created => 'invited', :destroyed => 'cancelled_invite'}} attr_accessor :no_default_feed private def create_associated_membership_on_accept(current_user) self.no_default_feed = true # Default feed has incorrect initiator. We're about to create a feed with the correct initiator. Membership.create_with_feed(user, :joinable => joinable, :user => user, :permissions => ) end def destroy_self_on_decline(current_user) self.no_default_feed = true # Default feed has incorrect initiator. We're about to create a feed with the correct initiator. destroy_with_feed(user) end # Don't create a destroyed feed if the user is accepting a membership invitation or a membership request exists for this User. # 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. def ensure_feed_creation with_feed(initiator) unless no_default_feed || joinable.membership_for?(user) || joinable.membership_request_for?(user) end end end |
.extend_membership_request ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/feedable/joinable_extensions.rb', line 69 def self.extend_membership_request MembershipRequest.class_eval do acts_as_feedable :parent => 'joinable', :delegate => {:references => 'user', :actions => {:created => 'requested', :destroyed => 'cancelled_request'}} private def create_associated_membership_on_grant(current_user, ) Membership.create_with_feed(current_user, :joinable => joinable, :user => user, :permissions => ) end end end |