Sha256: d19a26c4cecaed7442308f50a8136acbd243d98b9d80a8796dac654155fe947e

Contents?: true

Size: 990 Bytes

Versions: 24

Compression:

Stored size: 990 Bytes

Contents

event :update_public_link_on_create, :integrate, on: :create, when: :local? do
  update_public_link
end

event :remove_public_link_on_delete, :integrate, on: :delete, when: :local? do
  remove_public_links
end

event :update_public_link, after: :update_read_rule, when: :local? do
  return if content.blank?

  if who_can(:read).include? Card::AnyoneID
    create_public_links
  else
    remove_public_links
  end
end

private

def create_public_links
  path = attachment.public_path
  return if File.exist? path

  FileUtils.mkdir_p File.dirname(path)
  File.symlink attachment.path, path unless File.symlink? path
  create_versions_public_links
end

def create_versions_public_links
  attachment.versions.each_value do |version|
    next if File.symlink? version.public_path

    File.symlink version.path, version.public_path
  end
end

def remove_public_links
  symlink_dir = File.dirname attachment.public_path
  return unless Dir.exist? symlink_dir

  FileUtils.rm_rf symlink_dir
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
card-mod-carrierwave-0.18.1 set/abstract/attachment/local.rb
card-mod-carrierwave-0.18.0 set/abstract/attachment/local.rb
card-mod-carrierwave-0.17.0 set/abstract/attachment/local.rb
card-mod-carrierwave-0.16.0 set/abstract/attachment/local.rb
card-mod-carrierwave-0.15.6 set/abstract/attachment/local.rb
card-mod-carrierwave-0.15.5 set/abstract/attachment/local.rb
card-mod-carrierwave-0.15.4 set/abstract/attachment/local.rb
card-mod-carrierwave-0.15.3 set/abstract/attachment/local.rb
card-mod-carrierwave-0.15.2.pre1 set/abstract/attachment/local.rb
card-mod-carrierwave-0.15.1.1 set/abstract/attachment/local.rb
card-mod-carrierwave-0.15.1 set/abstract/attachment/local.rb
card-mod-carrierwave-0.15.0 set/abstract/attachment/local.rb
card-mod-carrierwave-0.14.2 set/abstract/attachment/local.rb
card-mod-carrierwave-0.14.1 set/abstract/attachment/local.rb
card-mod-carrierwave-0.14.0 set/abstract/attachment/local.rb
card-mod-carrierwave-0.13.4 set/abstract/attachment/local.rb
card-mod-carrierwave-0.13.3 set/abstract/attachment/local.rb
card-mod-carrierwave-0.13.2 set/abstract/attachment/local.rb
card-mod-carrierwave-0.13.1 set/abstract/attachment/local.rb
card-mod-carrierwave-0.13.0 set/abstract/attachment/local.rb