Class: Netfira::WebConnect::Model::Record::FileRecord

Inherits:
Netfira::WebConnect::Model::Record show all
Includes:
Paperclip::Glue
Defined in:
lib/netfira/web_connect/model.rb,
lib/netfira/web_connect/model/record/file_record.rb

Direct Known Subclasses

Netfira::WebConnect::Models::Image

Defined Under Namespace

Classes: Validator

Constant Summary

Constants included from Serializer

Serializer::EXCLUDE_FROM_SERIALIZE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Netfira::WebConnect::Model::Record

#as_readonly, #as_readwrite, find_by_origin_id, find_or_create_by_origin_id, find_or_initialize_by_origin_id, has_file?, has_languages?, #origin_id, related_classes, #reload, schema, sendable, sendable?, tree?, writable?, #write_with_type_casting

Methods included from Materialization

#materialize

Methods included from Digests

#digest

Methods included from Serializer

#to_s

Methods included from Relations

#relate, #unrelate

Methods inherited from Netfira::WebConnect::Model

#dispatch_event, plural_name, single_name

Class Method Details

.origin_keyObject



22
23
24
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 22

def origin_key
  :file_name
end

.table_nameObject



18
19
20
# 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

Instance Method Details

#<<(input) ⇒ Object



43
44
45
46
47
48
49
# 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_nameObject



76
77
78
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 76

def attachment_file_name
  file_name
end

#attachment_file_name=(value) ⇒ Object



80
81
82
# 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_sizeObject



84
85
86
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 84

def attachment_file_size
  size
end

#attachment_file_size=(value) ⇒ Object



88
89
90
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 88

def attachment_file_size=(value)
  self.size = value unless value.nil?
end

#checksumObject



51
52
53
54
# 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) ⇒ Object



56
57
58
59
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 56

def checksum=(value)
  @checksum = nil
  self[:checksum] = normalize_checksum(value)
end

#dataObject



61
62
63
64
65
66
67
# 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) ⇒ Object



69
70
71
72
73
74
# 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

#exists?Boolean Also known as: exist?

Returns:

  • (Boolean)


96
97
98
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 96

def exists?
  !!(remote_location || attachment.exists?)
end

#urlObject



92
93
94
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 92

def url
  exists? && remote_location || attachment.url
end