Module: EffectiveMembershipsUser

Extended by:
ActiveSupport::Concern
Defined in:
app/models/concerns/effective_memberships_user.rb

Overview

EffectiveMembershipsUser

Mark your user model with effective_memberships_user to get all the includes

Defined Under Namespace

Modules: Base, ClassMethods

Instance Method Summary collapse

Instance Method Details

#applicant_reviewer?Boolean

Roles

Returns:

  • (Boolean)


90
91
92
# File 'app/models/concerns/effective_memberships_user.rb', line 90

def applicant_reviewer?
  false
end

#build_representative(organization:) ⇒ Object

Find or build



68
69
70
# File 'app/models/concerns/effective_memberships_user.rb', line 68

def build_representative(organization:)
  representative(organization: organization) || representatives.build(organization: organization)
end

#can_stamp_wizard?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/models/concerns/effective_memberships_user.rb', line 94

def can_stamp_wizard?
  is?(:member) && membership.category.can_stamp_wizard?
end

#individual_membership_present?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'app/models/concerns/effective_memberships_user.rb', line 55

def individual_membership_present?
  membership.present? && !membership.marked_for_destruction?
end

#membership_categories_on(date) ⇒ Object



85
86
87
# File 'app/models/concerns/effective_memberships_user.rb', line 85

def membership_categories_on(date)
  membership_history_on(date).try(:membership_categories)
end

#membership_history_on(date) ⇒ Object



80
81
82
83
# File 'app/models/concerns/effective_memberships_user.rb', line 80

def membership_history_on(date)
  raise('expected a date') unless date.respond_to?(:strftime)
  membership_histories.find { |history| (history.start_on..history.end_on).cover?(date) } # Ruby 2.6 supports endless ranges
end

#membership_organizationsObject



76
77
78
# File 'app/models/concerns/effective_memberships_user.rb', line 76

def membership_organizations
  organizations.select { |organization| organization.is?(:member) && !organization.archived? }
end

#membership_present?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/models/concerns/effective_memberships_user.rb', line 51

def membership_present?
  individual_membership_present? || organization_membership_present?
end

#membershipsObject

Instance Methods



43
44
45
# File 'app/models/concerns/effective_memberships_user.rb', line 43

def memberships
  Array(membership) + membership_organizations.map(&:membership)
end

#memberships_ownersObject



47
48
49
# File 'app/models/concerns/effective_memberships_user.rb', line 47

def memberships_owners
  Array(self) + membership_organizations
end

#organization_membership_present?(except: nil) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/concerns/effective_memberships_user.rb', line 59

def organization_membership_present?(except: nil)
  organizations.reject(&:archived?).any? { |organization| organization != except && organization.membership_present? }
end

#organizationsObject



72
73
74
# File 'app/models/concerns/effective_memberships_user.rb', line 72

def organizations
  representatives.reject(&:marked_for_destruction?).map(&:organization)
end

#representative(organization:) ⇒ Object



63
64
65
# File 'app/models/concerns/effective_memberships_user.rb', line 63

def representative(organization:)
  representatives.find { |rep| rep.organization_id == organization.id } if organization
end