aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app/models/active_storage/filename.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activestorage/app/models/active_storage/filename.rb')
-rw-r--r--activestorage/app/models/active_storage/filename.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/activestorage/app/models/active_storage/filename.rb b/activestorage/app/models/active_storage/filename.rb
index 6a9889addf..df21078718 100644
--- a/activestorage/app/models/active_storage/filename.rb
+++ b/activestorage/app/models/active_storage/filename.rb
@@ -9,21 +9,23 @@ class ActiveStorage::Filename
@filename = filename
end
- # Filename.new("racecar.jpg").extname # => ".jpg"
- def extname
- File.extname(@filename)
+ # Filename.new("racecar.jpg").base # => "racecar"
+ def base
+ File.basename @filename, extension_with_delimiter
end
- # Filename.new("racecar.jpg").extension # => "jpg"
- def extension
- extname.from(1)
+ # Filename.new("racecar.jpg").extension_with_delimiter # => ".jpg"
+ def extension_with_delimiter
+ File.extname @filename
end
- # Filename.new("racecar.jpg").base # => "racecar"
- def base
- File.basename(@filename, extname)
+ # Filename.new("racecar.jpg").extension_without_delimiter # => "jpg"
+ def extension_without_delimiter
+ extension_with_delimiter.from(1).to_s
end
+ alias_method :extension, :extension_without_delimiter
+
# Filename.new("foo:bar.jpg").sanitized # => "foo-bar.jpg"
# Filename.new("foo/bar.jpg").sanitized # => "foo-bar.jpg"
#