Class: ShowCreator
- Inherits:
-
Struct
- Object
- Struct
- ShowCreator
- Defined in:
- app/models/job/show_creator.rb
Instance Attribute Summary collapse
-
#chart_params ⇒ Object
Returns the value of attribute chart_params.
-
#datetimes ⇒ Object
Returns the value of attribute datetimes.
-
#event ⇒ Object
Returns the value of attribute event.
-
#organization ⇒ Object
Returns the value of attribute organization.
-
#publish ⇒ Object
Returns the value of attribute publish.
-
#show_params ⇒ Object
Returns the value of attribute show_params.
Class Method Summary collapse
-
.enqueue(datetimes, show_params, chart_params, event, organization, publish = false) ⇒ Object
If datetime.length < 3, the shows will create right away.
Instance Method Summary collapse
Instance Attribute Details
#chart_params ⇒ Object
Returns the value of attribute chart_params
1 2 3 |
# File 'app/models/job/show_creator.rb', line 1 def chart_params @chart_params end |
#datetimes ⇒ Object
Returns the value of attribute datetimes
1 2 3 |
# File 'app/models/job/show_creator.rb', line 1 def datetimes @datetimes end |
#event ⇒ Object
Returns the value of attribute event
1 2 3 |
# File 'app/models/job/show_creator.rb', line 1 def event @event end |
#organization ⇒ Object
Returns the value of attribute organization
1 2 3 |
# File 'app/models/job/show_creator.rb', line 1 def organization @organization end |
#publish ⇒ Object
Returns the value of attribute publish
1 2 3 |
# File 'app/models/job/show_creator.rb', line 1 def publish @publish end |
#show_params ⇒ Object
Returns the value of attribute 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 |
#perform ⇒ Object
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 |