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.
-
#extension ⇒ Object
Overwritten with the extension of the file.
-
#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.
102 103 104 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 102 def [] end |
#basename ⇒ Object
Overwritten with the basename of the file.
86 87 88 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 86 def basename 'unused' end |
#cache_key ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 59 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
108 109 110 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 108 def can_upload? false end |
#extension ⇒ Object
Overwritten with the extension of the file.
91 92 93 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 91 def extension 'unused' end |
#failed? ⇒ Boolean
Overwritten with the conditions that indicate failure during processing.
124 125 126 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 124 def failed? raise 'Not implemented!' end |
#file_name ⇒ Object
Overwritten in UploadableFile with attachment filename.
96 97 98 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 96 def file_name 'unused' end |
#file_type ⇒ Object
55 56 57 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 55 def file_type Pageflow.config.file_types.find_by_model!(self.class) end |
#nested_files(model) ⇒ Object
47 48 49 50 51 52 53 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 47 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)
81 82 83 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 81 def original_url url end |
#parent_allows_type_for_nesting ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 27 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.add(: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
39 40 41 42 43 44 45 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 39 def parent_belongs_to_same_entry if parent_file.present? unless parent_file.using_entries.include?(entry) errors.add(: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.
139 140 141 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 139 def publish! raise 'Not implemented!' end |
#ready? ⇒ Boolean
Overwritten with the conditions that need to be fulfilled in order to (re)use the file.
119 120 121 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 119 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.
130 131 132 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 130 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).
114 115 116 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 114 def retryable? raise 'Not implemented!' end |
#url ⇒ Object
Overwritten if a file type provides a default url for its file.
74 75 76 |
# File 'app/models/concerns/pageflow/reusable_file.rb', line 74 def url '' end |