Class: Netfira::WebConnect::Model::Record::FileRecord
Defined Under Namespace
Classes: Validator
Constant Summary
Constants included
from Serializer
Serializer::EXCLUDE_FROM_SERIALIZE
Class Method Summary
collapse
Instance Method Summary
collapse
#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
#materialize
Methods included from Digests
#digest
Methods included from Serializer
#to_s
Methods included from Relations
#relate, #unrelate
#dispatch_event, plural_name, single_name
Class Method Details
.origin_key ⇒ Object
22
23
24
|
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 22
def origin_key
:file_name
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_name ⇒ Object
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_size ⇒ Object
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
|
#checksum ⇒ Object
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
|
#data ⇒ Object
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?
96
97
98
|
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 96
def exists?
!!(remote_location || attachment.exists?)
end
|
#url ⇒ Object
92
93
94
|
# File 'lib/netfira/web_connect/model/record/file_record.rb', line 92
def url
exists? && remote_location || attachment.url
end
|