Module: Fera::BelongsToReview

Extended by:
ActiveSupport::Concern
Included in:
Media
Defined in:
lib/fera/models/concerns/belongs_to_review.rb

Instance Method Summary collapse

Instance Method Details

#reviewObject



26
27
28
29
30
31
32
33
34
# File 'lib/fera/models/concerns/belongs_to_review.rb', line 26

def review
  if @review.present?
    @review
  elsif attributes.key?('review') && attributes['review'].present?
    Review.new(attributes['review'], true)
  elsif attributes.key?('review_id') && review_id.present?
    Review.find(review_id)
  end
end

#review=(review) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fera/models/concerns/belongs_to_review.rb', line 11

def review=(review)
  review_id = if review.is_a?(Review)
                review.id
              else
                review.try(:with_indifferent_access).try(:[], :id)
              end
  @review   = if review.is_a?(Review)
                review
              else
                Review.new(review, review_id.present?)
              end
  self.attributes['review_id'] = review_id
  self.attributes.delete('review')
end