Module: SubjModels::UserVideoModule

Defined in:
lib/subj_models/user_video.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(including_class) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/subj_models/user_video.rb', line 5

def self.included(including_class)

  including_class.class_eval do
    belongs_to :owner, class_name: 'User', foreign_key: :user_id

    belongs_to :brand
    has_and_belongs_to_many :user_specializations

    has_many :likes, dependent: :destroy
    has_many :liked_users, -> { uniq }, through: :likes, source: :user

    validates_presence_of :title
    validates_presence_of :brand
    validates_presence_of :owner

    has_attached_file :video_snapshot, default_url: '/images/default_video_snapshot.png', styles: { thumb: '300x300>' }
    validates_attachment_content_type :video_snapshot, content_type: /\Aimage\/.*\z/
    validates_attachment_size :video_snapshot, less_than: 10.megabytes

    has_attached_file :full_video, default_url: ''
    validates_attachment_content_type :full_video, content_type: /\Avideo\/.*\Z/

    validates_attachment_size :full_video, less_than: 300.megabytes

    has_attached_file :short_video, default_url: ''
    validates_attachment_content_type :short_video, content_type: /\Avideo\/.*\Z/
    validates_attachment_size :short_video, less_than: 100.megabytes

    before_full_video_post_process :rename_full_video
    before_short_video_post_process :rename_short_video
    before_video_snapshot_post_process :rename_video_snapshot
  end
end

Instance Method Details

#full_video_urlObject



48
49
50
# File 'lib/subj_models/user_video.rb', line 48

def full_video_url
  full_video&.url
end

#short_video_urlObject



52
53
54
# File 'lib/subj_models/user_video.rb', line 52

def short_video_url
  short_video&.url
end

#video_snapshot_thumbObject



44
45
46
# File 'lib/subj_models/user_video.rb', line 44

def video_snapshot_thumb
  video_snapshot&.url(:medium)
end

#video_snapshot_urlObject



40
41
42
# File 'lib/subj_models/user_video.rb', line 40

def video_snapshot_url
  video_snapshot&.url
end