class Netfira::WebConnect::Model::Record::FileRecord

Public Class Methods

origin_key() click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 22
def origin_key
  :file_name
end
table_name() click to toggle source
Calls superclass method
# File lib/netfira/web_connect/model/record/file_record.rb, line 18
def table_name
  self == Model::Record::FileRecord ? Models::Table.table_name : super
end

Public Instance Methods

<<(input) click to toggle source
Calls superclass method
# File lib/netfira/web_connect/model/record/file_record.rb, line 43
def <<(input)
  if input.is_a? Model::Record
    super input
  else
    self.data = input
  end
end
attachment_file_name() click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 76
def attachment_file_name
  file_name
end
attachment_file_name=(value) click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 80
def attachment_file_name=(value)
  self.file_name = value unless value.nil?
end
attachment_file_size() click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 84
def attachment_file_size
  size
end
attachment_file_size=(value) click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 88
def attachment_file_size=(value)
  self.size = value unless value.nil?
end
checksum() click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 51
def checksum
  bin = self[:checksum]
  @checksum ||= bin && Checksum.new(bin)
end
checksum=(value) click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 56
def checksum=(value)
  @checksum = nil
  self[:checksum] = normalize_checksum(value)
end
data() click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 61
def data
  @stream ||= if remote_location
    open remote_location.sub(/^file:/, '')
  elsif attachment.present?
    Paperclip.io_adapters.for attachment
  end
end
data=(value) click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 69
def data=(value)
  @stream = nil
  self.attachment = value
  value.rewind
  self.checksum = Checksum.of(value.read)
end
exist?()
Alias for: exists?
exists?() click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 96
def exists?
  !!(remote_location || attachment.exists?)
end
Also aliased as: exist?
url() click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 92
def url
  exists? && remote_location || attachment.url
end

Private Instance Methods

normalize_checksum(value) click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 107
def normalize_checksum(value)
  if Checksum === value
    value.b
  elsif String === value
    case value.length
      when 22 then OctaWord.from_base64(value).b
      when 32 then OctaWord.from_hex(value).b
      else value
    end
  else
    value
  end
end
set_file_defaults() click to toggle source
# File lib/netfira/web_connect/model/record/file_record.rb, line 103
def set_file_defaults
  self.locale ||= shop.locale
end