Class: ShowCreator

Inherits:
Struct
  • Object
show all
Defined in:
app/models/job/show_creator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#chart_paramsObject

Returns the value of attribute chart_params

Returns:

  • (Object)

    the current value of chart_params



1
2
3
# File 'app/models/job/show_creator.rb', line 1

def chart_params
  @chart_params
end

#datetimesObject

Returns the value of attribute datetimes

Returns:

  • (Object)

    the current value of datetimes



1
2
3
# File 'app/models/job/show_creator.rb', line 1

def datetimes
  @datetimes
end

#eventObject

Returns the value of attribute event

Returns:

  • (Object)

    the current value of event



1
2
3
# File 'app/models/job/show_creator.rb', line 1

def event
  @event
end

#organizationObject

Returns the value of attribute organization

Returns:

  • (Object)

    the current value of organization



1
2
3
# File 'app/models/job/show_creator.rb', line 1

def organization
  @organization
end

#publishObject

Returns the value of attribute publish

Returns:

  • (Object)

    the current value of publish



1
2
3
# File 'app/models/job/show_creator.rb', line 1

def publish
  @publish
end

#show_paramsObject

Returns the value of attribute show_params

Returns:

  • (Object)

    the current value of show_params



1
2
3
# File 'app/models/job/show_creator.rb', line 1

def show_params
  @show_params
end

Class Method Details

.enqueue(datetimes, show_params, chart_params, event, organization, publish = false) ⇒ Object

If datetime.length < 3, the shows will create right away. Otherwise, they’ll be queued



6
7
8
9
10
11
12
13
14
# File 'app/models/job/show_creator.rb', line 6

def self.enqueue(datetimes, show_params, chart_params, event, organization, publish = false)
  datetimes ||= []
  creator = ShowCreator.new(datetimes, show_params, chart_params, event, organization, publish)
  if datetimes.length < 3
    creator.perform
  else
    Delayed::Job.enqueue(creator)
  end
end

Instance Method Details

#offset(datetime_string, time_zone) ⇒ Object



35
36
37
# File 'app/models/job/show_creator.rb', line 35

def offset(datetime_string, time_zone)
  ActiveSupport::TimeZone.create(event.time_zone).parse(datetime_string).formatted_offset
end

#performObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/job/show_creator.rb', line 16

def perform
  ActiveRecord::Base.transaction do
    datetimes.each do |datetime_string|     
      @show = self.event.next_show 
      
      #clear the sections and replace them with whatever they entered
      @show.chart.sections = []
      @show.chart.update_attributes_from_params(chart_params)
      @show.update_attributes(show_params)
      @show.organization = organization
      @show.chart_id = @show.chart.id

      @show.datetime = DateTime.parse(datetime_string).change(:offset => offset(datetime_string, event.time_zone))
      @show.go!(publish)    
      @show.refresh_stats  
    end
  end
end