Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # grunt class for creating and updating the Video and its depedencies
- class VideoService
- attr_reader :video, :screenshot, :transcript, # :slide_set,
- :price, :attendee_price, :member_price
- def initialize(video, screenshot, transcript, slide_set,
- price, attendee_price, member_price)
- @video = video
- @screenshot = screenshot
- @transcript = transcript
- # @slide_set = slide_set
- @price = price
- @attendee_price = attendee_price
- @member_price = member_price
- end
- def save
- return false unless valid?
- begin
- # TODO: screaming for iteration
- Video.transaction do
- if @screenshot.new_record?
- @video.screenshot.destroy if @video.screenshot
- @screenshot.video = @video
- @screenshot.save!
- end
- if @transcript.new_record?
- @video.transcript.destroy if @video.transcript
- @transcript.video = @video
- @transcript.save!
- end
- # if @slide_set.new_record?
- # @video.slide_set.destroy if @video.slide_set
- # @slide_set.video = @video
- # @slide_set.save!
- # MiddleMan.worker(:unarchive_worker).unarchive_slide_set(@slide_set.id)
- # end
- if @price.new_record?
- @video.price.destroy if @video.price
- @price.video = @video
- @price.save!
- end
- if @attendee_price.new_record?
- @video.attendee_price.destroy if @video.attendee_price
- @attendee_price.video = @video
- @attendee_price.save!
- end
- if @member_price.new_record?
- @video.member_price.destroy if @video.member_price
- @member_price.video = @video
- @member_price.save!
- end
- @video.save!
- true
- end
- rescue
- false
- end
- end
- def valid?
- @video.valid? && @screenshot.valid? && @transcript.valid? &&
- # @slide_set.valid? &&
- @price.valid? && @attendee_price.valid? &&
- @member_price.valid?
- end
- def update_attributes(video_attributes, screenshot_file, transcript_file,
- slide_set_file, price_attributes, attendee_price_attributes,
- member_price_attributes)
- @video.attributes = video_attributes
- unless screenshot_file.blank?
- @screenshot = Screenshot.new(:uploaded_data => screenshot_file)
- end
- unless transcript_file.blank?
- @transcript = Transcript.new(:uploaded_data => transcript_file)
- end
- unless slide_set_file.blank?
- @slide_set = SlideSet.new(:uploaded_data => slide_set_file)
- end
- @price.attributes = price_attributes
- @attendee_price.attributes = attendee_price_attributes
- @member_price.attributes = member_price_attributes
- save
- end
- end
Add Comment
Please, Sign In to add comment