Sha256: f69d6a36052dbf5851f78536a3941c2bd7500bb6c3cdcd1dcc482faf1999caf3
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
module Adhocracy module ActsAsMember extend ActiveSupport::Concern module ClassMethods def acts_as_member(options = {}) has_many :memberships, as: :member, class_name: "Adhocracy::Membership" has_many :membership_invitations, as: :member, class_name: "Adhocracy::MembershipInvitation" has_many :membership_requests, as: :member, class_name: "Adhocracy::MembershipRequest" send :include, InstanceMethods end end module InstanceMethods def groups MembershipAssociation.new(member: self).list_groups_for_membership end def group_invitations MembershipAssociation.new(member: self). list_groups_for_membership_invitation end def membership_requests MembershipAssociation.new(member: self). list_groups_for_membership_request end def join_group(group) MembershipAssociation.new(member: self, group: group).create_membership end def request_membership_in(group) MembershipAssociation.new(member: self, group: group). create_membership_request end def leave_group(group) MembershipAssociation.new(member: self, group: group).destroy_membership end def member_of?(group) MembershipAssociation.new(member: self, group: group).verify_membership end def invited_to?(group, params = {}) params.merge!({ member: self, group: group }) MembershipAssociation.new(params).verify_membership_invitation end def requested_membership_in?(group, params = {}) params.merge!({ member: self, group: group }) MembershipAssociation.new(params).verify_membership_request end end end end ActiveRecord::Base.send :include, Adhocracy::ActsAsMember
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
adhocracy-0.3.0 | lib/adhocracy/acts_as_member.rb |
adhocracy-0.2.0 | lib/adhocracy/acts_as_member.rb |