Class: Para::Cloneable::AttachmentsCloner
- Inherits:
-
Object
- Object
- Para::Cloneable::AttachmentsCloner
- Defined in:
- lib/para/cloneable/attachments_cloner.rb
Instance Attribute Summary collapse
-
#clone ⇒ Object
readonly
Returns the value of attribute clone.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
Instance Method Summary collapse
- #clone! ⇒ Object
-
#initialize(original, clone) ⇒ AttachmentsCloner
constructor
A new instance of AttachmentsCloner.
Constructor Details
#initialize(original, clone) ⇒ AttachmentsCloner
Returns a new instance of AttachmentsCloner.
6 7 8 9 |
# File 'lib/para/cloneable/attachments_cloner.rb', line 6 def initialize(original, clone) @original = original @clone = clone end |
Instance Attribute Details
#clone ⇒ Object (readonly)
Returns the value of attribute clone.
4 5 6 |
# File 'lib/para/cloneable/attachments_cloner.rb', line 4 def clone @clone end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
4 5 6 |
# File 'lib/para/cloneable/attachments_cloner.rb', line 4 def original @original end |
Instance Method Details
#clone! ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/para/cloneable/attachments_cloner.rb', line 11 def clone! return unless defined?(ActiveStorage) = original.class.reflections.select { |k, v| k.to_s.match(/_attachment\z/) && v.[:class_name] == "ActiveStorage::Attachment" } .each do |name, reflection| = original.send(name) next unless association_name = name.gsub(/_attachment\z/, "") Para::ActiveStorageDownloader.new().download_blob_to_tempfile do |tempfile| clone.send(association_name).attach({ io: tempfile, filename: .blob.filename, content_type: .blob.content_type }) end end end |