Module: Pageflow::HostedFile

Extended by:
ActiveSupport::Concern
Includes:
UploadedFile
Included in:
AudioFile, TextTrackFile, VideoFile
Defined in:
app/models/concerns/pageflow/hosted_file.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UploadedFile

#file_type, #nested_files, #parent_allows_type_for_nesting, #parent_belongs_to_same_entry

Class Method Details

.columns(t) ⇒ Object

Deprecated.

Write a migration instead



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/concerns/pageflow/hosted_file.rb', line 84

def self.columns(t)
  t.belongs_to(:entry, index: true)
  t.belongs_to(:uploader, index: true)

  t.string(:state)
  t.string(:rights)

  t.string(:attachment_on_filesystem_file_name)
  t.string(:attachment_on_filesystem_content_type)
  t.integer(:attachment_on_filesystem_file_size, limit: 8)
  t.datetime(:attachment_on_filesystem_updated_at)

  t.string(:attachment_on_s3_file_name)
  t.string(:attachment_on_s3_content_type)
  t.integer(:attachment_on_s3_file_size, limit: 8)
  t.datetime(:attachment_on_s3_updated_at)

  t.timestamps
end

Instance Method Details

#attachmentObject



40
41
42
# File 'app/models/concerns/pageflow/hosted_file.rb', line 40

def attachment
  attachment_on_s3.present? ? attachment_on_s3 : attachment_on_filesystem
end

#attachment=(value) ⇒ Object



44
45
46
# File 'app/models/concerns/pageflow/hosted_file.rb', line 44

def attachment=(value)
  self.attachment_on_filesystem = value
end

#basenameObject



60
61
62
# File 'app/models/concerns/pageflow/hosted_file.rb', line 60

def basename
  File.basename(attachment.original_filename, '.*')
end

#cache_keyObject



74
75
76
77
78
79
80
81
# File 'app/models/concerns/pageflow/hosted_file.rb', line 74

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

#keep_on_filesystem_after_upload_to_s3?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'app/models/concerns/pageflow/hosted_file.rb', line 48

def keep_on_filesystem_after_upload_to_s3?
  false
end

#original_urlObject



70
71
72
# File 'app/models/concerns/pageflow/hosted_file.rb', line 70

def original_url
  url
end

#ready?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'app/models/concerns/pageflow/hosted_file.rb', line 56

def ready?
  attachment_on_s3.present?
end

#retryable?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/concerns/pageflow/hosted_file.rb', line 52

def retryable?
  can_retry?
end

#urlObject



64
65
66
67
68
# File 'app/models/concerns/pageflow/hosted_file.rb', line 64

def url
  if attachment_on_s3.present?
    attachment.url
  end
end