Sha256: 7279d42730b15d98500fb8464f04cb449a891b9a28443904f00e8cd588bb2543

Contents?: true

Size: 1017 Bytes

Versions: 67

Compression:

Stored size: 1017 Bytes

Contents

# frozen_string_literal: true

# == Schema Information
#
# Table name: alchemy_essence_files
#
#  id            :integer          not null, primary key
#  attachment_id :integer
#  title         :string
#  css_class     :string
#  created_at    :datetime         not null
#  updated_at    :datetime         not null
#  link_text     :string
#

module Alchemy
  class EssenceFile < BaseRecord
    belongs_to :attachment, optional: true
    acts_as_essence ingredient_column: "attachment"

    def attachment_url
      return if attachment.nil?

      routes.download_attachment_path(
        id: attachment.id,
        name: attachment.slug,
        format: attachment.suffix,
      )
    end

    def preview_text(max = 30)
      return "" if attachment.blank?

      attachment.name.to_s[0..max - 1]
    end

    # Returns a serialized ingredient value for json api
    def serialized_ingredient
      attachment_url
    end

    private

    def routes
      @routes ||= Engine.routes.url_helpers
    end
  end
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
alchemy_cms-5.3.8 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.9 app/models/alchemy/essence_file.rb
alchemy_cms-5.3.7 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.8 app/models/alchemy/essence_file.rb
alchemy_cms-5.3.6 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.7 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.6 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.5 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.4 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.3 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.2 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.1 app/models/alchemy/essence_file.rb
alchemy_cms-5.3.5 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.0 app/models/alchemy/essence_file.rb
alchemy_cms-5.3.4 app/models/alchemy/essence_file.rb
alchemy_cms-6.0.0.pre.rc7 app/models/alchemy/essence_file.rb
alchemy_cms-5.3.3 app/models/alchemy/essence_file.rb
alchemy_cms-5.3.2 app/models/alchemy/essence_file.rb
alchemy_cms-5.3.1 app/models/alchemy/essence_file.rb
alchemy_cms-5.3.0 app/models/alchemy/essence_file.rb