Guest User

Untitled

a guest
Mar 17th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. # grunt class for creating and updating the Video and its depedencies
  2. class VideoService
  3.  
  4. attr_reader :video, :screenshot, :transcript, # :slide_set,
  5. :price, :attendee_price, :member_price
  6.  
  7. def initialize(video, screenshot, transcript, slide_set,
  8. price, attendee_price, member_price)
  9. @video = video
  10. @screenshot = screenshot
  11. @transcript = transcript
  12. # @slide_set = slide_set
  13. @price = price
  14. @attendee_price = attendee_price
  15. @member_price = member_price
  16. end
  17.  
  18. def save
  19. return false unless valid?
  20. begin
  21. # TODO: screaming for iteration
  22. Video.transaction do
  23. if @screenshot.new_record?
  24. @video.screenshot.destroy if @video.screenshot
  25. @screenshot.video = @video
  26. @screenshot.save!
  27. end
  28.  
  29. if @transcript.new_record?
  30. @video.transcript.destroy if @video.transcript
  31. @transcript.video = @video
  32. @transcript.save!
  33. end
  34.  
  35. # if @slide_set.new_record?
  36. # @video.slide_set.destroy if @video.slide_set
  37. # @slide_set.video = @video
  38. # @slide_set.save!
  39. # MiddleMan.worker(:unarchive_worker).unarchive_slide_set(@slide_set.id)
  40. # end
  41.  
  42. if @price.new_record?
  43. @video.price.destroy if @video.price
  44. @price.video = @video
  45. @price.save!
  46. end
  47.  
  48. if @attendee_price.new_record?
  49. @video.attendee_price.destroy if @video.attendee_price
  50. @attendee_price.video = @video
  51. @attendee_price.save!
  52. end
  53.  
  54. if @member_price.new_record?
  55. @video.member_price.destroy if @video.member_price
  56. @member_price.video = @video
  57. @member_price.save!
  58. end
  59.  
  60. @video.save!
  61. true
  62. end
  63. rescue
  64. false
  65. end
  66. end
  67.  
  68. def valid?
  69. @video.valid? && @screenshot.valid? && @transcript.valid? &&
  70. # @slide_set.valid? &&
  71. @price.valid? && @attendee_price.valid? &&
  72. @member_price.valid?
  73. end
  74.  
  75. def update_attributes(video_attributes, screenshot_file, transcript_file,
  76. slide_set_file, price_attributes, attendee_price_attributes,
  77. member_price_attributes)
  78. @video.attributes = video_attributes
  79. unless screenshot_file.blank?
  80. @screenshot = Screenshot.new(:uploaded_data => screenshot_file)
  81. end
  82. unless transcript_file.blank?
  83. @transcript = Transcript.new(:uploaded_data => transcript_file)
  84. end
  85. unless slide_set_file.blank?
  86. @slide_set = SlideSet.new(:uploaded_data => slide_set_file)
  87. end
  88. @price.attributes = price_attributes
  89. @attendee_price.attributes = attendee_price_attributes
  90. @member_price.attributes = member_price_attributes
  91. save
  92. end
  93.  
  94. end
Add Comment
Please, Sign In to add comment