Class: Comp
- Inherits:
-
Object
- Object
- Comp
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- app/models/comp.rb
Instance Attribute Summary collapse
-
#benefactor ⇒ Object
Returns the value of attribute benefactor.
-
#comped_count ⇒ Object
Returns the value of attribute comped_count.
-
#details ⇒ Object
Returns the value of attribute details.
-
#memberships ⇒ Object
Returns the value of attribute memberships.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#order ⇒ Object
Returns the value of attribute order.
-
#recipient ⇒ Object
Returns the value of attribute recipient.
-
#show ⇒ Object
Returns the value of attribute show.
-
#tickets ⇒ Object
Returns the value of attribute tickets.
-
#uncomped_count ⇒ Object
Returns the value of attribute uncomped_count.
Instance Method Summary collapse
- #has_recipient? ⇒ Boolean
-
#initialize(show, tickets_or_ids, memberships, recipient, benefactor, notes = nil) ⇒ Comp
constructor
tickets can be an array of tickets_ids or an array of tickets.
- #persisted? ⇒ Boolean
- #submit ⇒ Object
- #valid_recipient_and_benefactor ⇒ Object
Constructor Details
#initialize(show, tickets_or_ids, memberships, recipient, benefactor, notes = nil) ⇒ Comp
tickets can be an array of tickets_ids or an array of tickets
12 13 14 15 16 17 18 19 20 |
# File 'app/models/comp.rb', line 12 def initialize(show, tickets_or_ids, memberships, recipient, benefactor, notes=nil) @show = show @tickets = [] @memberships = memberships load_tickets(tickets_or_ids) @recipient = Person.find(recipient) unless recipient.blank? @benefactor = benefactor @notes = notes end |
Instance Attribute Details
#benefactor ⇒ Object
Returns the value of attribute benefactor.
8 9 10 |
# File 'app/models/comp.rb', line 8 def benefactor @benefactor end |
#comped_count ⇒ Object
Returns the value of attribute comped_count.
9 10 11 |
# File 'app/models/comp.rb', line 9 def comped_count @comped_count end |
#details ⇒ Object
Returns the value of attribute details.
9 10 11 |
# File 'app/models/comp.rb', line 9 def details @details end |
#memberships ⇒ Object
Returns the value of attribute memberships.
8 9 10 |
# File 'app/models/comp.rb', line 8 def memberships @memberships end |
#notes ⇒ Object
Returns the value of attribute notes.
8 9 10 |
# File 'app/models/comp.rb', line 8 def notes @notes end |
#order ⇒ Object
Returns the value of attribute order.
8 9 10 |
# File 'app/models/comp.rb', line 8 def order @order end |
#recipient ⇒ Object
Returns the value of attribute recipient.
8 9 10 |
# File 'app/models/comp.rb', line 8 def recipient @recipient end |
#show ⇒ Object
Returns the value of attribute show.
8 9 10 |
# File 'app/models/comp.rb', line 8 def show @show end |
#tickets ⇒ Object
Returns the value of attribute tickets.
8 9 10 |
# File 'app/models/comp.rb', line 8 def tickets @tickets end |
#uncomped_count ⇒ Object
Returns the value of attribute uncomped_count.
9 10 11 |
# File 'app/models/comp.rb', line 9 def uncomped_count @uncomped_count end |
Instance Method Details
#has_recipient? ⇒ Boolean
38 39 40 |
# File 'app/models/comp.rb', line 38 def has_recipient? !recipient.blank? end |
#persisted? ⇒ Boolean
42 43 44 |
# File 'app/models/comp.rb', line 42 def persisted? false end |
#submit ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/models/comp.rb', line 46 def submit ActiveRecord::Base.transaction do create_order(@tickets, @memberships, @recipient, @benefactor, @notes) self.comped_count = tickets.size self.uncomped_count = 0 end end |
#valid_recipient_and_benefactor ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/comp.rb', line 22 def valid_recipient_and_benefactor if @recipient.nil? errors.add(:base, "Please select a person to comp to or create a new person record") return end if @benefactor.nil? errors.add(:base, "Please select a benefactor") return end unless @benefactor.current_organization.eql? @recipient.organization errors.add(:base, "Recipient and benefactor are from different organizations") end end |