Class: Testimonials::Testimonial

Inherits:
ApplicationRecord show all
Defined in:
app/models/testimonials/testimonial.rb

Overview

One testimonial — text or video. Author attribution is optional and stored as loose fields (no foreign key to the host's user table) so the model is portable across apps with different user models.

Constant Summary collapse

KINDS =
%w[text video].freeze
STATUSES =
%w[pending approved archived].freeze
SOURCES =
%w[widget page nps].freeze

Instance Method Summary collapse

Instance Method Details

#avatar_attached?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'app/models/testimonials/testimonial.rb', line 50

def avatar_attached?
  respond_to?(:avatar) && avatar.attached?
end

#display_nameObject



54
55
56
# File 'app/models/testimonials/testimonial.rb', line 54

def display_name
  name.presence || (author_id.present? ? "##{author_id}" : nil)
end

#poster_attached?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/testimonials/testimonial.rb', line 46

def poster_attached?
  respond_to?(:poster) && poster.attached?
end

#quoteObject

The curated pull-quote when the admin picked one, else the full text.



59
60
61
# File 'app/models/testimonials/testimonial.rb', line 59

def quote
  best_line.presence || body
end

#video?Boolean

Returns:

  • (Boolean)


40
# File 'app/models/testimonials/testimonial.rb', line 40

def video? = kind == 'video'

#video_attached?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'app/models/testimonials/testimonial.rb', line 42

def video_attached?
  respond_to?(:video_file) && video_file.attached?
end