Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Active Storage docs [ci skip] #30456

Merged
merged 1 commit into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions activestorage/app/models/active_storage/blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# A blob is a record that contains the metadata about a file and a key for where that file resides on the service.
# Blobs can be created in two ways:
#
# 1) Subsequent to the file being uploaded server-side to the service via <tt>create_after_upload!</tt>.
# 2) Ahead of the file being directly uploaded client-side to the service via <tt>create_before_direct_upload!</tt>.
# 1. Subsequent to the file being uploaded server-side to the service via <tt>create_after_upload!</tt>.
# 2. Ahead of the file being directly uploaded client-side to the service via <tt>create_before_direct_upload!</tt>.
#
# The first option doesn't require any client-side JavaScript integration, and can be used by any other back-end
# service that deals with files. The second option is faster, since you're not using your own server as a staging
Expand Down
18 changes: 13 additions & 5 deletions activestorage/app/models/active_storage/filename.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,33 @@ def initialize(filename)
@filename = filename
end

# Filename.new("racecar.jpg").base # => "racecar"
# Returns the basename of the filename.
#
# ActiveStorage::Filename.new("racecar.jpg").base # => "racecar"
def base
File.basename @filename, extension_with_delimiter
end

# Filename.new("racecar.jpg").extension_with_delimiter # => ".jpg"
# Returns the extension with delimiter of the filename.
#
# ActiveStorage::Filename.new("racecar.jpg").extension_with_delimiter # => ".jpg"
def extension_with_delimiter
File.extname @filename
end

# Filename.new("racecar.jpg").extension_without_delimiter # => "jpg"
# Returns the extension without delimiter of the filename.
#
# ActiveStorage::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"
# Returns the sanitized filename.
#
# ActiveStorage::Filename.new("foo:bar.jpg").sanitized # => "foo-bar.jpg"
# ActiveStorage::Filename.new("foo/bar.jpg").sanitized # => "foo-bar.jpg"
#
# ...and any other character unsafe for URLs or storage is converted or stripped.
def sanitized
Expand Down
2 changes: 1 addition & 1 deletion activestorage/lib/active_storage/attached/one.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def attach(attachable)
ActiveStorage::Attachment.create!(record: record, name: name, blob: create_blob_from(attachable))
end

# Returns true if an attachment has been made.
# Returns +true+ if an attachment has been made.
#
# class User < ActiveRecord::Base
# has_one_attached :avatar
Expand Down
2 changes: 1 addition & 1 deletion activestorage/lib/active_storage/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def delete(key)
raise NotImplementedError
end

# Return true if a file exists at the +key+.
# Return +true+ if a file exists at the +key+.
def exist?(key)
raise NotImplementedError
end
Expand Down