Module: Pageflow::ReusableFile

Extended by:
ActiveSupport::Concern
Included in:
UploadableFile
Defined in:
app/models/concerns/pageflow/reusable_file.rb

Instance Method Summary collapse

Instance Method Details

#attachments_for_exportObject

Overwritten with the list of attachments of the file type that should get included in export archives.



97
98
99
# File 'app/models/concerns/pageflow/reusable_file.rb', line 97

def attachments_for_export
  []
end

#basenameObject

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_keyObject



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

Returns:

  • (Boolean)


103
104
105
# File 'app/models/concerns/pageflow/reusable_file.rb', line 103

def can_upload?
  false
end

#failed?Boolean

Overwritten with the conditions that indicate failure during processing.

Returns:

  • (Boolean)


119
120
121
# File 'app/models/concerns/pageflow/reusable_file.rb', line 119

def failed?
  raise 'Not implemented!'
end

#file_nameObject

Overwritten in UploadableFile with attachment filename.



91
92
93
# File 'app/models/concerns/pageflow/reusable_file.rb', line 91

def file_name
  'unused'
end

#file_typeObject



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_urlObject

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_nestingObject



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[:base] << 'File type of provided parent file does not permit nesting files of '\
                       "type #{self.class.name}"
    end
  end
end

#parent_belongs_to_same_entryObject



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[: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.



134
135
136
# File 'app/models/concerns/pageflow/reusable_file.rb', line 134

def publish!
  raise 'Not implemented!'
end

#ready?Boolean

Overwritten with the conditions that need to be fulfilled in order to (re)use the file.

Returns:

  • (Boolean)


114
115
116
# File 'app/models/concerns/pageflow/reusable_file.rb', line 114

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.



125
126
127
# File 'app/models/concerns/pageflow/reusable_file.rb', line 125

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).

Returns:

  • (Boolean)


109
110
111
# File 'app/models/concerns/pageflow/reusable_file.rb', line 109

def retryable?
  raise 'Not implemented!'
end

#urlObject

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