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.
-
#categories ⇒ Object
We can’t use the polymorphic has_many.
-
#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
- #paid_fees_through?(period = nil) ⇒ Boolean
-
#revise! ⇒ Object
Admin updating membership info.
- #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
67 68 69 |
# File 'app/models/effective/membership.rb', line 67 def self.max_number maximum('number_as_integer') || 0 end |
Instance Method Details
#build_membership_category(category:) ⇒ Object
find or build
114 115 116 |
# File 'app/models/effective/membership.rb', line 114 def build_membership_category(category:) membership_category(category: category) || membership_categories.build(category: category) end |
#categories ⇒ Object
We can’t use the polymorphic has_many. So this is a helper.
89 90 91 |
# File 'app/models/effective/membership.rb', line 89 def categories membership_categories.reject(&:marked_for_destruction?).map(&:category) end |
#category ⇒ Object
We might want to use singular memberships.
98 99 100 101 |
# File 'app/models/effective/membership.rb', line 98 def category raise('expected singular usage but there are more than one membership') if categories.length > 1 categories.first end |
#category_id ⇒ Object
103 104 105 106 |
# File 'app/models/effective/membership.rb', line 103 def category_id raise('expected singular usage but there are more than one membership') if categories.length > 1 categories.first.id end |
#category_ids ⇒ Object
93 94 95 |
# File 'app/models/effective/membership.rb', line 93 def category_ids membership_categories.reject(&:marked_for_destruction?).map(&:category_id) end |
#change_fees_paid_period ⇒ Object
143 144 145 |
# File 'app/models/effective/membership.rb', line 143 def change_fees_paid_period fees_paid_period end |
#change_fees_paid_period=(date) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'app/models/effective/membership.rb', line 147 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
122 123 124 |
# File 'app/models/effective/membership.rb', line 122 def fees_paid? paid_fees_through?(EffectiveMemberships.Registrar.current_period) end |
#good_standing? ⇒ Boolean
118 119 120 |
# File 'app/models/effective/membership.rb', line 118 def good_standing? !bad_standing? end |
#membership_category(category:) ⇒ Object
108 109 110 111 |
# File 'app/models/effective/membership.rb', line 108 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 |
#paid_fees_through?(period = nil) ⇒ Boolean
126 127 128 129 130 131 |
# File 'app/models/effective/membership.rb', line 126 def paid_fees_through?(period = nil) period ||= EffectiveMemberships.Registrar.current_period return false if fees_paid_period.blank? fees_paid_period >= period end |
#revise! ⇒ Object
Admin updating membership info
161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/models/effective/membership.rb', line 161 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 |
#to_s ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/models/effective/membership.rb', line 71 def to_s return 'membership' if owner.blank? summary = [ owner.to_s, 'is', (categories.to_sentence), 'member', "##{number_was}", "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
133 134 135 136 137 138 139 140 141 |
# File 'app/models/effective/membership.rb', line 133 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 |