Class: ClowneActiveStorage::Resolvers::AttachmentAssociation
- Inherits:
-
Object
- Object
- ClowneActiveStorage::Resolvers::AttachmentAssociation
- Defined in:
- lib/clowne_active_storage/resolvers/attachment_association.rb
Overview
Clone the files attached to source and attach the clones to the record
Instance Attribute Summary collapse
-
#declaration ⇒ Object
readonly
Returns the value of attribute declaration.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(source, record, declaration) ⇒ AttachmentAssociation
constructor
A new instance of AttachmentAssociation.
Constructor Details
#initialize(source, record, declaration) ⇒ AttachmentAssociation
Returns a new instance of AttachmentAssociation.
15 16 17 18 19 |
# File 'lib/clowne_active_storage/resolvers/attachment_association.rb', line 15 def initialize(source, record, declaration) @source = source @record = record @declaration = declaration end |
Instance Attribute Details
#declaration ⇒ Object (readonly)
Returns the value of attribute declaration.
13 14 15 |
# File 'lib/clowne_active_storage/resolvers/attachment_association.rb', line 13 def declaration @declaration end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
13 14 15 |
# File 'lib/clowne_active_storage/resolvers/attachment_association.rb', line 13 def record @record end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
13 14 15 |
# File 'lib/clowne_active_storage/resolvers/attachment_association.rb', line 13 def source @source end |
Class Method Details
.call(source, record, declaration) ⇒ Object
7 8 9 10 11 |
# File 'lib/clowne_active_storage/resolvers/attachment_association.rb', line 7 def self.call(source, record, declaration, **) new(source, record, declaration).call rescue Errno::ENOENT record end |
Instance Method Details
#call ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/clowne_active_storage/resolvers/attachment_association.rb', line 21 def call return record unless source_association.attached? source_association..each do || open_attached do |tempfile| record_association.attach( io: tempfile, filename: .filename, content_type: .content_type ) end end record end |