Class: MembershipComp

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeMembershipComp

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

#benefactorObject

Returns the value of attribute benefactor.



14
15
16
# File 'app/models/membership_comp.rb', line 14

def benefactor
  @benefactor
end

#ends_atObject

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_typeObject

Returns the value of attribute membership_type.



14
15
16
# File 'app/models/membership_comp.rb', line 14

def membership_type
  @membership_type
end

#notesObject

Returns the value of attribute notes.



14
15
16
# File 'app/models/membership_comp.rb', line 14

def notes
  @notes
end

#number_of_membershipsObject

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

#organizationObject

Returns the value of attribute organization.



14
15
16
# File 'app/models/membership_comp.rb', line 14

def organization
  @organization
end

#peopleObject

Returns the value of attribute people.



14
15
16
# File 'app/models/membership_comp.rb', line 14

def people
  @people
end

#person_idObject

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_idObject

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_idObject

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_emailObject

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_priceObject

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_messageObject

Returns the value of attribute welcome_message.



14
15
16
# File 'app/models/membership_comp.rb', line 14

def welcome_message
  @welcome_message
end

Instance Method Details

#awardObject



79
80
81
82
# File 'app/models/membership_comp.rb', line 79

def award
  return false unless valid?
  MembershipCompJob.enqueue self
end

#clear_errorsObject

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_pastObject



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_orgObject



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_idsObject



36
37
38
# File 'app/models/membership_comp.rb', line 36

def people_ids
  people.nil? ? [] : people.collect(&:id)
end

#performObject



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.welcome_message  = self.welcome_message
      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

Returns:

  • (Boolean)


32
33
34
# File 'app/models/membership_comp.rb', line 32

def persisted?
  false
end

#we_have_some_peopleObject



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