Files
manyfold/app/models/concerns/path_builder.rb
T
James Smith 6dd588a1a4 re-add block parameters for Ruby 3.3 compat
This was changed for the new `it` in Ruby 3.4, but linuxserver images
can't use 3.4 yet, so we re-add the parameter name (as it) for 3.3.
2025-01-15 11:48:42 +00:00

32 lines
764 B
Ruby

module PathBuilder
extend ActiveSupport::Concern
def formatted_path
SiteSettings.model_path_template.gsub(/{.+?}/) do |token|
case token
when "{tags}"
(tags.count > 0) ?
File.join(tags.order(taggings_count: :desc, name: :asc).map { |it| it.to_s.parameterize }) :
"@untagged"
when "{creator}"
path_component(creator) || "@unattributed"
when "{collection}"
path_component(collection) || "@uncollected"
when "{modelName}"
path_component(self)
when "{modelId}"
"##{id}"
else
token
end
end
end
private
def path_component(object)
return nil if object.nil?
SiteSettings.safe_folder_names ? object.slug : object.name
end
end