Module: Pageflow::ReusableFile
- Extended by:
- ActiveSupport::Concern
- Included in:
- UploadableFile
- Defined in:
- app/models/concerns/pageflow/reusable_file.rb
Instance Method Summary collapse
-
#attachments_for_export ⇒ Object
Overwritten with the list of attachments of the file type that should get included in export archives.
-
#basename ⇒ Object
Overwritten with the basename of the file.
- #cache_key ⇒ Object
-
#can_upload? ⇒ Boolean
Overwritten in UploadableFile based on initial state_machine-state.
-
#failed? ⇒ Boolean
Overwritten with the conditions that indicate failure during processing.
-
#file_name ⇒ Object
Overwritten in UploadableFile with attachment filename.
- #file_type ⇒ Object
- #nested_files(model) ⇒ Object
-
#original_url ⇒ Object
Overwritten in case of a file type providing its original (unprocessed) file for download in the editor.
- #parent_allows_type_for_nesting ⇒ Object
- #parent_belongs_to_same_entry ⇒ Object
-
#publish! ⇒ Object
Gets called to trigger the ‘file_uploaded` event in the upload state machine of UploadableFile.
-
#ready? ⇒ Boolean
Overwritten with the conditions that need to be fulfilled in order to (re)use the file.
-
#retry! ⇒ Object
If the conditions in retryable? are met then this method specifies what should happen when a retry is requested, depending on the including class’ processing state machine.
-
#retryable? ⇒ Boolean
Overwritten with the conditions that need to be fulfilled in order to ‘retry` whatever the file does (i.e. processing/transcoding).
-
#url ⇒ Object
Overwritten if a file type provides a default url for its file.
Instance Method Details
#attachments_for_export ⇒ Object
Overwritten with the list of attachments of the file type that should get included in export archives.
92 93 94 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 92 def [] end |
#basename ⇒ Object
Overwritten with the basename of the file.
81 82 83 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 81 def basename 'unused' end |
#cache_key ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 54 def cache_key # Ensure the cache key changes when the state changes. There are # cases during processing where the state is updated multiple # times in a single second. Since `cache_key` relies on # `updated_at`, which only is acurate to the second, we need to # prevent caching outdated information. "#{super}-#{state}" end |
#can_upload? ⇒ Boolean
Overwritten in UploadableFile based on initial state_machine-state. Defaults to false for files that only use the ReusableFile module
98 99 100 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 98 def can_upload? false end |
#failed? ⇒ Boolean
Overwritten with the conditions that indicate failure during processing.
114 115 116 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 114 def failed? raise 'Not implemented!' end |
#file_name ⇒ Object
Overwritten in UploadableFile with attachment filename.
86 87 88 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 86 def file_name 'unused' end |
#file_type ⇒ Object
50 51 52 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 50 def file_type Pageflow.config.file_types.find_by_model!(self.class) end |
#nested_files(model) ⇒ Object
42 43 44 45 46 47 48 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 42 def nested_files(model) model_table_name = model.table_name model .select("#{model_table_name}.*") .where("#{model_table_name}.parent_file_id = #{id} AND "\ "#{model_table_name}.parent_file_model_type = '#{self.class.name}'") end |
#original_url ⇒ Object
Overwritten in case of a file type providing its original (unprocessed) file for download in the editor. Defaults to the default url of the file (see above)
76 77 78 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 76 def original_url url end |
#parent_allows_type_for_nesting ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 22 def parent_allows_type_for_nesting if parent_file.present? parent_class = parent_file.class file_type_of_parent = Pageflow.config.file_types.find_by_model!(parent_class) models_of_nested_file_types = file_type_of_parent.nested_file_types.map(&:model) unless models_of_nested_file_types.include?(self.class) errors[:base] << 'File type of provided parent file does not permit nesting files of '\ "type #{self.class.name}" end end end |
#parent_belongs_to_same_entry ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 34 def parent_belongs_to_same_entry if parent_file.present? unless parent_file.using_entries.include?(entry) errors[:base] << 'Parent file does not belong to same entry as nested file' end end end |
#publish! ⇒ Object
Gets called to trigger the ‘file_uploaded` event in the upload state machine of UploadableFile. Files that are not uploaded through the editor (and therefore not using the upload state machine of UploadableFile) can overwrite this method to trigger whatever the file does (i.e. processing/transcoding), depending on the including class’ processing state machine.
129 130 131 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 129 def publish! raise 'Not implemented!' end |
#ready? ⇒ Boolean
Overwritten with the conditions that need to be fulfilled in order to (re)use the file.
109 110 111 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 109 def ready? raise 'Not implemented!' end |
#retry! ⇒ Object
If the conditions in retryable? are met then this method specifies what should happen when a retry is requested, depending on the including class’ processing state machine.
120 121 122 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 120 def retry! raise 'Not implemented!' end |
#retryable? ⇒ Boolean
Overwritten with the conditions that need to be fulfilled in order to ‘retry` whatever the file does (i.e. processing/transcoding).
104 105 106 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 104 def retryable? raise 'Not implemented!' end |
#url ⇒ Object
Overwritten if a file type provides a default url for its file.
69 70 71 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 69 def url '' end |