Class: ActiveStorage::Attached::Changes::CreateOne
Do not use. This class is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Inherits: | Object |
Defined in: | activestorage/lib/active_storage/attached/changes/create_one.rb |
Class Method Summary
- .new(name, record, attachable) ⇒ CreateOne constructor
Instance Attribute Summary
- #attachable readonly
- #name readonly
- #record readonly
Instance Method Summary
- #attachment
- #blob
- #save
- #upload
- #attachment_service_name private
- #build_attachment private
- #find_attachment private
- #find_or_build_attachment private
- #find_or_build_blob private
Constructor Details
.new(name, record, attachable) ⇒ CreateOne
# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 10
def initialize(name, record, attachable) @name, @record, @attachable = name, record, attachable blob.identify_without_saving end
Instance Attribute Details
#attachable (readonly)
[ GitHub ]#name (readonly)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 8
attr_reader :name, :record, :attachable
#record (readonly)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 8
attr_reader :name, :record, :attachable
Instance Method Details
#attachment
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 15
def @attachment ||= end
#attachment_service_name (private)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 120
def service_name = record. [name]. [:service_name] if service_name.is_a?(Proc) service_name = service_name.call(record) ActiveStorage::Blob.validate_service_configuration(service_name, record.class, name) end service_name end
#blob
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 19
def blob @blob ||= find_or_build_blob end
#build_attachment (private)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 64
def ActiveStorage::Attachment.new(record: record, name: name, blob: blob) end
#find_attachment (private)
[ GitHub ]#find_or_build_attachment (private)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 54
def || end
#find_or_build_blob (private)
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 68
def find_or_build_blob case attachable when ActiveStorage::Blob attachable when ActionDispatch::Http::UploadedFile ActiveStorage::Blob.build_after_unfurling( io: attachable.open, filename: attachable.original_filename, content_type: attachable.content_type, record: record, service_name: ) when Rack::Test::UploadedFile ActiveStorage::Blob.build_after_unfurling( io: attachable.respond_to?(:open) ? attachable.open : attachable, filename: attachable.original_filename, content_type: attachable.content_type, record: record, service_name: ) when Hash ActiveStorage::Blob.build_after_unfurling( **attachable.reverse_merge( record: record, service_name: ).symbolize_keys ) when String ActiveStorage::Blob.find_signed!(attachable, record: record) when File ActiveStorage::Blob.build_after_unfurling( io: attachable, filename: File.basename(attachable), record: record, service_name: ) when Pathname ActiveStorage::Blob.build_after_unfurling( io: attachable.open, filename: File.basename(attachable), record: record, service_name: ) else raise( ArgumentError, "Could not find or build blob: expected attachable, " \ "got #{attachable.inspect}" ) end end
#save
[ GitHub ]#upload
[ GitHub ]# File 'activestorage/lib/active_storage/attached/changes/create_one.rb', line 23
def upload case attachable when ActionDispatch::Http::UploadedFile blob.upload_without_unfurling(attachable.open) when Rack::Test::UploadedFile blob.upload_without_unfurling( attachable.respond_to?(:open) ? attachable.open : attachable ) when Hash blob.upload_without_unfurling(attachable.fetch(:io)) when File blob.upload_without_unfurling(attachable) when Pathname blob.upload_without_unfurling(attachable.open) when ActiveStorage::Blob when String else raise( ArgumentError, "Could not upload: expected attachable, " \ "got #{attachable.inspect}" ) end end