Class: MemberWalkup
- Inherits:
-
Object
- Object
- MemberWalkup
- Includes:
- ActiveModel::Conversion, ActiveModel::MassAssignmentSecurity, ActiveModel::Validations, ActiveRecord::Reflection
- Defined in:
- app/models/member_walkup.rb
Defined Under Namespace
Constant Summary collapse
- MemberNotFound =
Class.new(Exception)
- ShowNotFound =
Class.new(Exception)
- TicketTypeNotFound =
Class.new(Exception)
- TicketsNotAvailable =
Class.new(Exception)
Instance Attribute Summary collapse
-
#member ⇒ Object
readonly
Returns the value of attribute member.
-
#member_uuid ⇒ Object
Returns the value of attribute member_uuid.
-
#show ⇒ Object
readonly
Returns the value of attribute show.
-
#show_id ⇒ Object
Returns the value of attribute show_id.
-
#ticket ⇒ Object
readonly
Returns the value of attribute ticket.
-
#ticket_type ⇒ Object
readonly
Returns the value of attribute ticket_type.
Instance Method Summary collapse
- #assign_attributes(values, options = {}) ⇒ Object
- #cart ⇒ Object
- #checkout ⇒ Object
-
#initialize(attributes = {}) {|_self| ... } ⇒ MemberWalkup
constructor
A new instance of MemberWalkup.
- #payment ⇒ Object
- #persisted? ⇒ Boolean
- #save ⇒ Object
Constructor Details
#initialize(attributes = {}) {|_self| ... } ⇒ MemberWalkup
Returns a new instance of MemberWalkup.
26 27 28 29 |
# File 'app/models/member_walkup.rb', line 26 def initialize(attributes = {}) assign_attributes(attributes) yield(self) if block_given? end |
Instance Attribute Details
#member ⇒ Object (readonly)
Returns the value of attribute member.
12 13 14 |
# File 'app/models/member_walkup.rb', line 12 def member @member end |
#member_uuid ⇒ Object
Returns the value of attribute member_uuid.
17 18 19 |
# File 'app/models/member_walkup.rb', line 17 def member_uuid @member_uuid end |
#show ⇒ Object (readonly)
Returns the value of attribute show.
13 14 15 |
# File 'app/models/member_walkup.rb', line 13 def show @show end |
#show_id ⇒ Object
Returns the value of attribute show_id.
18 19 20 |
# File 'app/models/member_walkup.rb', line 18 def show_id @show_id end |
#ticket ⇒ Object (readonly)
Returns the value of attribute ticket.
14 15 16 |
# File 'app/models/member_walkup.rb', line 14 def ticket @ticket end |
#ticket_type ⇒ Object (readonly)
Returns the value of attribute ticket_type.
15 16 17 |
# File 'app/models/member_walkup.rb', line 15 def ticket_type @ticket_type end |
Instance Method Details
#assign_attributes(values, options = {}) ⇒ Object
31 32 33 34 35 |
# File 'app/models/member_walkup.rb', line 31 def assign_attributes(values, = {}) sanitize_for_mass_assignment(values, [:as]).each do |k, v| send("#{k}=", v) end end |
#cart ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/member_walkup.rb', line 37 def cart return nil unless valid? unless @cart @cart = Cart.create # Lock the ticket and update the ticket record locked = Ticket.lock(ticket, ticket_type, @cart) @ticket = locked[0] unless locked.blank? end @cart end |
#checkout ⇒ Object
50 51 52 53 |
# File 'app/models/member_walkup.rb', line 50 def checkout return nil unless valid? @checkout ||= Checkout.new(cart, payment) end |
#payment ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'app/models/member_walkup.rb', line 59 def payment return nil unless valid? unless @payment @payment = CashPayment.new @payment.customer = member.person end @payment end |
#persisted? ⇒ Boolean
69 70 71 |
# File 'app/models/member_walkup.rb', line 69 def persisted? false end |
#save ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/member_walkup.rb', line 73 def save return false unless valid? raise TicketTypeNotFound, "Valid for $0 member only tickets, but none are setup." unless ticket_type if 1 > ticket_type.available('storefront', member) raise TicketsNotAvailable, "No more tickets are available." end # Finish checking out finished = checkout.finish # Reload the ticket on success ticket.reload if finished finished end |