Class: MembershipComp
- Inherits:
-
Object
- Object
- MembershipComp
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- app/models/membership_comp.rb
Constant Summary collapse
- QUEUE =
"comp"
Instance Attribute Summary collapse
-
#benefactor ⇒ Object
Returns the value of attribute benefactor.
-
#ends_at ⇒ Object
Returns the value of attribute ends_at.
-
#membership_type ⇒ Object
Returns the value of attribute membership_type.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#number_of_memberships ⇒ Object
Returns the value of attribute number_of_memberships.
-
#organization ⇒ Object
Returns the value of attribute organization.
-
#people ⇒ Object
Returns the value of attribute people.
-
#person_id ⇒ Object
Returns the value of attribute person_id.
-
#search_id ⇒ Object
Returns the value of attribute search_id.
-
#segment_id ⇒ Object
Returns the value of attribute segment_id.
-
#send_email ⇒ Object
Returns the value of attribute send_email.
-
#sold_price ⇒ Object
Returns the value of attribute sold_price.
-
#welcome_message ⇒ Object
Returns the value of attribute welcome_message.
Instance Method Summary collapse
- #award ⇒ Object
-
#clear_errors ⇒ Object
Weird Rails/DJ bug where calling validate on membership_comp caused the errors to hang around.
- #expiration_date_cannot_be_in_the_past ⇒ Object
-
#initialize ⇒ MembershipComp
constructor
A new instance of MembershipComp.
- #people_belong_to_this_org ⇒ Object
- #people_ids ⇒ Object
- #perform ⇒ Object
- #persisted? ⇒ Boolean
- #we_have_some_people ⇒ Object
Constructor Details
#initialize ⇒ MembershipComp
Returns a new instance of MembershipComp.
28 29 30 |
# File 'app/models/membership_comp.rb', line 28 def initialize self.people = [] end |
Instance Attribute Details
#benefactor ⇒ Object
Returns the value of attribute benefactor.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def benefactor @benefactor end |
#ends_at ⇒ Object
Returns the value of attribute ends_at.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def ends_at @ends_at end |
#membership_type ⇒ Object
Returns the value of attribute membership_type.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def membership_type @membership_type end |
#notes ⇒ Object
Returns the value of attribute notes.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def notes @notes end |
#number_of_memberships ⇒ Object
Returns the value of attribute number_of_memberships.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def number_of_memberships @number_of_memberships end |
#organization ⇒ Object
Returns the value of attribute organization.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def organization @organization end |
#people ⇒ Object
Returns the value of attribute people.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def people @people end |
#person_id ⇒ Object
Returns the value of attribute person_id.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def person_id @person_id end |
#search_id ⇒ Object
Returns the value of attribute search_id.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def search_id @search_id end |
#segment_id ⇒ Object
Returns the value of attribute segment_id.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def segment_id @segment_id end |
#send_email ⇒ Object
Returns the value of attribute send_email.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def send_email @send_email end |
#sold_price ⇒ Object
Returns the value of attribute sold_price.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def sold_price @sold_price end |
#welcome_message ⇒ Object
Returns the value of attribute welcome_message.
14 15 16 |
# File 'app/models/membership_comp.rb', line 14 def @welcome_message end |
Instance Method Details
#award ⇒ Object
79 80 81 82 |
# File 'app/models/membership_comp.rb', line 79 def award return false unless valid? MembershipCompJob.enqueue self end |
#clear_errors ⇒ Object
Weird Rails/DJ bug where calling validate on membership_comp caused the errors to hang around. DJ would choke when Syck tried to deserialize the errors attr The error message was horrible and misleading (uninitialized constant Syck::Syck)
It’s probably because we’re including ActiveModel::Validations on MembershipComp
56 57 58 |
# File 'app/models/membership_comp.rb', line 56 def clear_errors @errors = nil end |
#expiration_date_cannot_be_in_the_past ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/membership_comp.rb', line 66 def expiration_date_cannot_be_in_the_past if !ends_at.present? errors.add(:base, "Please enter a membership expiration date") end if DateTime.parse(ends_at) < Date.today errors.add(:base, "Membership expiration date can't be in the past") end rescue errors.add(:base, "Please enter a membership expiration date") end |
#people_belong_to_this_org ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/models/membership_comp.rb', line 40 def people_belong_to_this_org people.each do |person| Rails.logger.info "FLARG #{person.organization.id} #{organization}" if person.organization != organization errors.add(:base, "Person does not belong to this organization. Please contact Artful.ly support if this problem persists.") end end end |
#people_ids ⇒ Object
36 37 38 |
# File 'app/models/membership_comp.rb', line 36 def people_ids people.nil? ? [] : people.collect(&:id) end |
#perform ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/models/membership_comp.rb', line 84 def perform self.people.each do |person| next if person.email.blank? next if person.company? memberships = [] self.number_of_memberships.to_i.times do membership = Membership.for(self.membership_type) membership.ends_at = self.ends_at membership.sold_price = 0 membership.total_paid = 0 membership. = self. membership.send_email = self.send_email membership.save memberships << membership end comp = Comp.new(nil, [], memberships, person, self.benefactor) comp.notes = self.notes comp.submit end end |
#persisted? ⇒ Boolean
32 33 34 |
# File 'app/models/membership_comp.rb', line 32 def persisted? false end |
#we_have_some_people ⇒ Object
60 61 62 63 64 |
# File 'app/models/membership_comp.rb', line 60 def we_have_some_people if people.blank? errors.add(:base, "You haven't selected any people to receive memberships") end end |