Class: Fiona7::Builder::LazyBlobCopier
- Inherits:
-
Object
- Object
- Fiona7::Builder::LazyBlobCopier
- Includes:
- Fiona7::BinaryFilesCleaner
- Defined in:
- lib/fiona7/builder/lazy_blob_copier.rb
Overview
This class implements a lazy blob copy/rename operation.
Blob copy is trivial: an existing blob is taken and copied to the destination object.
Blob rename occurs, when an apparent copy is executed, that is the blob that is copied is already associated with this object (and only with this object)
The lazy part of this class is the fact that you need to call .save! on the passed destination obj to actually persist the changes in the obj
NOTE: there is an exception to the above: renaming a blob in standalone mode executes immediately
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(attrs = {}) ⇒ LazyBlobCopier
constructor
A new instance of LazyBlobCopier.
Methods included from Fiona7::BinaryFilesCleaner
#delete_unused, #unrelease_unused
Constructor Details
#initialize(attrs = {}) ⇒ LazyBlobCopier
28 29 30 31 32 33 34 35 36 |
# File 'lib/fiona7/builder/lazy_blob_copier.rb', line 28 def initialize(attrs={}) @destination_obj = attrs[:destination_obj] @attribute = attrs[:attr_name] @source_blob_id = attrs[:source_blob_id] @filename = attrs[:filename] @content_type = attrs[:content_type] @basename, @ext = *split_filename(@filename) end |
Instance Method Details
#call ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fiona7/builder/lazy_blob_copier.rb', line 38 def call validate_input! @blob_obj = Fiona7::WriteObj.find(@source_blob_id.to_i) @source_obj = find_unique_source_obj if @source_obj == nil link_orphaned_blob elsif @destination_obj == @source_obj rename_or_assign else copy end return {id: @destination_blob_id} end |