Class: Effective::Membership
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::Membership
- Defined in:
- app/models/effective/membership.rb
Instance Attribute Summary collapse
-
#current_action ⇒ Object
Returns the value of attribute current_action.
Class Method Summary collapse
Instance Method Summary collapse
-
#build_membership_category(category:) ⇒ Object
find or build.
-
#build_membership_status(status:) ⇒ Object
find or build.
-
#categories ⇒ Object
We can’t use the polymorphic has_many.
- #categories_sentence ⇒ Object
-
#category ⇒ Object
We might want to use singular memberships.
- #category_id ⇒ Object
- #category_ids ⇒ Object
- #change_fees_paid_period ⇒ Object
- #change_fees_paid_period=(date) ⇒ Object
- #fees_paid? ⇒ Boolean
- #good_standing? ⇒ Boolean
- #membership_category(category:) ⇒ Object
- #membership_status(status:) ⇒ Object
- #paid_fees_through?(period = nil) ⇒ Boolean
- #reregistered? ⇒ Boolean
-
#revise! ⇒ Object
Admin updating membership info.
-
#status ⇒ Object
We might want to use singular memberships.
- #status_id ⇒ Object
- #status_ids ⇒ Object
-
#statuses ⇒ Object
We can’t use the polymorphic has_many.
- #statuses_sentence ⇒ Object
- #to_s ⇒ Object
- #unpaid_fees_through?(period = nil) ⇒ Boolean
Instance Attribute Details
#current_action ⇒ Object
Returns the value of attribute current_action.
5 6 7 |
# File 'app/models/effective/membership.rb', line 5 def current_action @current_action end |
Class Method Details
.max_number ⇒ Object
72 73 74 |
# File 'app/models/effective/membership.rb', line 72 def self.max_number maximum('number_as_integer') || 0 end |
Instance Method Details
#build_membership_category(category:) ⇒ Object
find or build
126 127 128 |
# File 'app/models/effective/membership.rb', line 126 def build_membership_category(category:) membership_category(category: category) || membership_categories.build(category: category) end |
#build_membership_status(status:) ⇒ Object
find or build
162 163 164 |
# File 'app/models/effective/membership.rb', line 162 def build_membership_status(status:) membership_status(status: status) || membership_statuses.build(status: status) end |
#categories ⇒ Object
We can’t use the polymorphic has_many. So this is a helper.
97 98 99 |
# File 'app/models/effective/membership.rb', line 97 def categories membership_categories.reject(&:marked_for_destruction?).map(&:category) end |
#categories_sentence ⇒ Object
116 117 118 |
# File 'app/models/effective/membership.rb', line 116 def categories_sentence categories.map(&:to_s).to_sentence.presence || 'None' end |
#category ⇒ Object
We might want to use singular memberships.
106 107 108 109 |
# File 'app/models/effective/membership.rb', line 106 def category raise('expected singular usage but there are more than one membership category') if categories.length > 1 categories.first end |
#category_id ⇒ Object
111 112 113 114 |
# File 'app/models/effective/membership.rb', line 111 def category_id raise('expected singular usage but there are more than one membership category') if categories.length > 1 categories.first.id end |
#category_ids ⇒ Object
101 102 103 |
# File 'app/models/effective/membership.rb', line 101 def category_ids membership_categories.reject(&:marked_for_destruction?).map(&:category_id) end |
#change_fees_paid_period ⇒ Object
195 196 197 |
# File 'app/models/effective/membership.rb', line 195 def change_fees_paid_period fees_paid_period end |
#change_fees_paid_period=(date) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'app/models/effective/membership.rb', line 199 def change_fees_paid_period=(date) if date.blank? return assign_attributes(fees_paid_period: nil, fees_paid_through_period: nil) end date = (date.respond_to?(:strftime) ? date : Date.parse(date)) period = EffectiveMemberships.Registrar.period(date: date) period_end_on = EffectiveMemberships.Registrar.period_end_on(date: date) assign_attributes(fees_paid_period: period, fees_paid_through_period: period_end_on) end |
#fees_paid? ⇒ Boolean
174 175 176 |
# File 'app/models/effective/membership.rb', line 174 def fees_paid? paid_fees_through?(EffectiveMemberships.Registrar.current_period) end |
#good_standing? ⇒ Boolean
170 171 172 |
# File 'app/models/effective/membership.rb', line 170 def good_standing? !bad_standing? end |
#membership_category(category:) ⇒ Object
120 121 122 123 |
# File 'app/models/effective/membership.rb', line 120 def membership_category(category:) raise('expected a category') unless category.class.respond_to?(:effective_memberships_category?) membership_categories.find { |mc| mc.category_id == category.id && mc.category_type == category.class.name } end |
#membership_status(status:) ⇒ Object
156 157 158 159 |
# File 'app/models/effective/membership.rb', line 156 def membership_status(status:) raise('expected a status') unless status.class.respond_to?(:effective_memberships_status?) membership_statuses.find { |ms| ms.status_id == status.id && ms.status_type == status.class.name } end |
#paid_fees_through?(period = nil) ⇒ Boolean
178 179 180 181 182 183 |
# File 'app/models/effective/membership.rb', line 178 def paid_fees_through?(period = nil) period ||= EffectiveMemberships.Registrar.current_period return false if fees_paid_period.blank? fees_paid_period >= period end |
#reregistered? ⇒ Boolean
166 167 168 |
# File 'app/models/effective/membership.rb', line 166 def reregistered? registration_on.present? && joined_on.present? && registration_on > joined_on end |
#revise! ⇒ Object
Admin updating membership info
213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'app/models/effective/membership.rb', line 213 def revise! save! period = EffectiveMemberships.Registrar.current_period return true if paid_fees_through?(period) # Otherwise build fees right now EffectiveMemberships.Registrar.create_renewal_fees!(self, period: period) EffectiveMemberships.Registrar.create_late_fees!(self, period: period) EffectiveMemberships.Registrar.update_membership_status!(self, period: period) true end |
#status ⇒ Object
We might want to use singular memberships.
146 147 148 149 |
# File 'app/models/effective/membership.rb', line 146 def status raise('expected singular usage but there are more than one membership status') if statuses.length > 1 statuses.first end |
#status_id ⇒ Object
151 152 153 154 |
# File 'app/models/effective/membership.rb', line 151 def status_id raise('expected singular usage but there are more than one membership status') if statuses.length > 1 statuses.first.id end |
#status_ids ⇒ Object
137 138 139 |
# File 'app/models/effective/membership.rb', line 137 def status_ids membership_statuses.reject(&:marked_for_destruction?).map(&:status_id) end |
#statuses ⇒ Object
We can’t use the polymorphic has_many. So this is a helper.
133 134 135 |
# File 'app/models/effective/membership.rb', line 133 def statuses membership_statuses.reject(&:marked_for_destruction?).map(&:status) end |
#statuses_sentence ⇒ Object
141 142 143 |
# File 'app/models/effective/membership.rb', line 141 def statuses_sentence statuses.map(&:to_s).to_sentence.presence || 'None' end |
#to_s ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/models/effective/membership.rb', line 76 def to_s return 'membership' if owner.blank? summary = [ owner.to_s, 'is', (statuses.to_sentence if statuses.present?), (categories.to_sentence if categories.present?), 'member', ("##{number_was}" if number_was.present?), "who joined #{joined_on&.strftime('%F') || '-'}", ("and last registered #{registration_on.strftime('%F')}" if registration_on > joined_on), (". Membership is Not In Good Standing because #{bad_standing_reason}" if bad_standing?) ].compact.join(' ') (summary + '.').html_safe end |
#unpaid_fees_through?(period = nil) ⇒ Boolean
185 186 187 188 189 190 191 192 193 |
# File 'app/models/effective/membership.rb', line 185 def unpaid_fees_through?(period = nil) period ||= EffectiveMemberships.Registrar.current_period return false if joined_on.blank? return false unless joined_on < period return true if fees_paid_period.blank? fees_paid_period < period end |