Class: ImportableAttachments::Attachment

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Paperclip::Glue, Rails::MarkRequirements, SmarterDates
Defined in:
app/models/importable_attachments/attachment.rb

Direct Known Subclasses

Attachment

Constant Summary collapse

CONTENT_URL =
::Configuration.for('attachments').url
CONTENT_PATH =
::Configuration.for('attachments').path

Instance Method Summary collapse

Instance Method Details

#io_stream_mime_typeObject

:call-seq: io_stream_mime_type

yields the files MIME::Type



105
106
107
108
# File 'app/models/importable_attachments/attachment.rb', line 105

def io_stream_mime_type
  mime = new_record? ? io_stream.content_type : magic_mime_type
  MIME::Types[mime].first
end

#magic_mime_typeObject

:call-seq: magic_mime_type

yields a saved attachments mime_type according to libmagic



115
116
117
118
119
# File 'app/models/importable_attachments/attachment.rb', line 115

def magic_mime_type
  return if new_record?
  return unless File.exists? io_stream.path
  FileMagic.mime.file(io_stream.path).split(/;\s*/).first
end

#revision_numberObject

:call-seq: revision_number

yields an integer representing the version-index

NOTE: paper_trail manages version-tracking automatically



88
89
90
91
92
93
94
95
96
97
98
# File 'app/models/importable_attachments/attachment.rb', line 88

def revision_number
  ver = version
  case
  when live? then
    versions.count
  when ver then
    ver.index
  else
    0
  end
end