Class: Ticket::Template

Inherits:
Object
  • Object
show all
Defined in:
app/models/ticket/template.rb

Overview

TODO: This class is supposed to encapsulate creating a ticket so that whoever is creating the Ticket (section, show, etc..) will always have the tickets created properly. Instead, this class take a hash of whatever the called passed in, so Tickets can be created with whatever attrs are passed in. We want it to be very easy for callers to create tickets the exact same way every time.

Do not use this class or method. Instead, use Ticket.create_many

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Template

Returns a new instance of Template.



9
10
11
# File 'app/models/ticket/template.rb', line 9

def initialize(attrs = {})
  @attributes = attrs
end

Instance Method Details

#attributesObject



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

def attributes
  @attributes
end

#buildObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/ticket/template.rb', line 25

def build
  count = @attributes.delete(:count).to_i
  organization_id = @attributes.delete(:organization_id)
  show_id = @attributes.delete(:show_id)
  
  tickets = []
  count.times.collect do 
    t = Ticket.new(attributes)
    t.organization_id = organization_id
    t.show_id = show_id
    t.set_uuid
    tickets << t
  end
  tickets
end

#collectObject



13
# File 'app/models/ticket/template.rb', line 13

def collect; self; end

#flattenObject



15
# File 'app/models/ticket/template.rb', line 15

def flatten; self; end

#update_attributes(attrs) ⇒ Object



21
22
23
# File 'app/models/ticket/template.rb', line 21

def update_attributes(attrs)
  @attributes.merge!(attrs)
end