Class: MemberWalkup

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Conversion, ActiveModel::MassAssignmentSecurity, ActiveModel::Validations, ActiveRecord::Reflection
Defined in:
app/models/member_walkup.rb

Defined Under Namespace

Classes: Checkout, Order

Constant Summary collapse

MemberNotFound =
Class.new(Exception)
ShowNotFound =
Class.new(Exception)
TicketTypeNotFound =
Class.new(Exception)
TicketsNotAvailable =
Class.new(Exception)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) {|_self| ... } ⇒ MemberWalkup

Returns a new instance of MemberWalkup.

Yields:

  • (_self)

Yield Parameters:

  • _self (MemberWalkup)

    the object that the method was called on



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

#memberObject (readonly)

Returns the value of attribute member.



12
13
14
# File 'app/models/member_walkup.rb', line 12

def member
  @member
end

#member_uuidObject

Returns the value of attribute member_uuid.



17
18
19
# File 'app/models/member_walkup.rb', line 17

def member_uuid
  @member_uuid
end

#showObject (readonly)

Returns the value of attribute show.



13
14
15
# File 'app/models/member_walkup.rb', line 13

def show
  @show
end

#show_idObject

Returns the value of attribute show_id.



18
19
20
# File 'app/models/member_walkup.rb', line 18

def show_id
  @show_id
end

#ticketObject (readonly)

Returns the value of attribute ticket.



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

def ticket
  @ticket
end

#ticket_typeObject (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, options = {})
  sanitize_for_mass_assignment(values, options[:as]).each do |k, v|
    send("#{k}=", v)
  end
end

#cartObject



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

#checkoutObject



50
51
52
53
# File 'app/models/member_walkup.rb', line 50

def checkout
  return nil unless valid?
  @checkout ||= Checkout.new(cart, payment)
end

#paymentObject



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

Returns:

  • (Boolean)


69
70
71
# File 'app/models/member_walkup.rb', line 69

def persisted?
  false
end

#saveObject

Raises:



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