app/models/alchemy/attachment.rb in alchemy_cms-5.0.10 vs app/models/alchemy/attachment.rb in alchemy_cms-5.1.0.beta1

- old
+ new

@@ -26,19 +26,33 @@ dragonfly_accessor :file, app: :alchemy_attachments do after_assign { |f| write_attribute(:file_mime_type, f.mime_type) } end - stampable stamper_class_name: Alchemy.user_class.name + stampable stamper_class_name: Alchemy.user_class_name has_many :essence_files, class_name: "Alchemy::EssenceFile", foreign_key: "attachment_id" has_many :contents, through: :essence_files has_many :elements, through: :contents has_many :pages, through: :elements # We need to define this method here to have it available in the validations below. class << self + # The class used to generate URLs for attachments + # + # @see Alchemy::Attachment::Url + def url_class + @_url_class ||= Alchemy::Attachment::Url + end + + # Set a different attachment url class + # + # @see Alchemy::Attachment::Url + def url_class=(klass) + @_url_class = klass + end + def searchable_alchemy_resource_attributes %w(name file_name) end def allowed_filetypes @@ -74,16 +88,19 @@ "size" => read_attribute(:file_size), "error" => errors[:file].join, } end + def url(options = {}) + if file + self.class.url_class.new(self).call(options) + end + end + # An url save filename without format suffix def slug CGI.escape(file_name.gsub(/\.#{extension}$/, "").tr(".", " ")) end - - alias_method :urlname, :slug - deprecate urlname: :slug, deprecator: Alchemy::Deprecation # Checks if the attachment is restricted, because it is attached on restricted pages only def restricted? pages.any? && pages.not_restricted.blank? end