Sha256: d167c17a5806a123d2842ae50358146a8609d2f1e39758553cb999e1ab4d665c

Contents?: true

Size: 1.04 KB

Versions: 29

Compression:

Stored size: 1.04 KB

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
#  creator_id    :integer
#  updater_id    :integer
#  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.urlname,
        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

29 entries across 29 versions & 1 rubygems

Version Path
alchemy_cms-4.6.7 app/models/alchemy/essence_file.rb
alchemy_cms-4.6.6 app/models/alchemy/essence_file.rb
alchemy_cms-4.6.5 app/models/alchemy/essence_file.rb
alchemy_cms-4.5.1 app/models/alchemy/essence_file.rb
alchemy_cms-4.4.5 app/models/alchemy/essence_file.rb
alchemy_cms-4.6.4 app/models/alchemy/essence_file.rb
alchemy_cms-4.6.3 app/models/alchemy/essence_file.rb
alchemy_cms-4.6.2 app/models/alchemy/essence_file.rb
alchemy_cms-4.6.1 app/models/alchemy/essence_file.rb
alchemy_cms-4.6.0 app/models/alchemy/essence_file.rb
alchemy_cms-4.5.0 app/models/alchemy/essence_file.rb
alchemy_cms-4.4.4 app/models/alchemy/essence_file.rb
alchemy_cms-4.4.3 app/models/alchemy/essence_file.rb
alchemy_cms-4.4.2 app/models/alchemy/essence_file.rb
alchemy_cms-4.4.1 app/models/alchemy/essence_file.rb
alchemy_cms-4.4.0 app/models/alchemy/essence_file.rb
alchemy_cms-4.3.2 app/models/alchemy/essence_file.rb
alchemy_cms-4.2.4 app/models/alchemy/essence_file.rb
alchemy_cms-4.3.1 app/models/alchemy/essence_file.rb
alchemy_cms-4.2.3 app/models/alchemy/essence_file.rb