Sha256: 65123336ef7fe7f25c886ae1ffad129ffc1996d40943617f26e24ce7e9e3a656

Contents?: true

Size: 765 Bytes

Versions: 7

Compression:

Stored size: 765 Bytes

Contents

module Ecm::Videos
  class Category < ActiveRecord::Base
    # markup support
    include Models::MarkupConcern
    markup :description

    # acts as published
    include ActsAsPublished::ActiveRecord
    acts_as_published

    has_many :videos, -> { order(position: :asc) }

    validates :locale, :name, :markup_language, presence: true

    after_initialize :set_defaults, if: :new_record?

    def preview_image
      videos.first.try(:preview_image)
    end

    def published_preview_image_url(style)
      return unless video = videos.published.first
      video.clip.url(style)
    end

    def videos_count
      videos.count
    end

    private

    def set_defaults
      self.markup_language = Configuration.default_markup_language
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ecm_videos-2.1.1 app/models/ecm/videos/category.rb
ecm_videos-2.1.0 app/models/ecm/videos/category.rb
ecm_videos-2.0.0 app/models/ecm/videos/category.rb
ecm_videos-1.0.4 app/models/ecm/videos/category.rb
ecm_videos-1.0.3 app/models/ecm/videos/category.rb
ecm_videos-1.0.2 app/models/ecm/videos/category.rb
ecm_videos-1.0.1 app/models/ecm/videos/category.rb