Class: ActiveFedora::File
- Inherits:
-
Object
- Object
- ActiveFedora::File
show all
- Extended by:
- Querying, ActiveModel::Callbacks, ActiveSupport::Autoload, ActiveTriples::Properties
- Includes:
- AttributeMethods, Callbacks, Common, Attributes, Streaming, FilePersistence, Identifiable, Inheritance, Scoping, Versionable, ActiveModel::Dirty
- Defined in:
- lib/active_fedora/file.rb
Overview
An LDP NonRDFSource. The base class for a bytestream stored in the repository.
Defined Under Namespace
Modules: Attributes, Streaming
Constant Summary
AttributeMethods::AttrNames, AttributeMethods::BLACKLISTED_CLASS_METHODS
Constants included
from Callbacks
Callbacks::CALLBACKS
Instance Method Summary
collapse
Methods included from Querying
default_sort_params, extended
Methods included from Scoping
#initialize_internals_callback, #populate_with_current_scope_attributes
#id, #id=, #uri
#[], #[]=, #attribute_for_inspect, #attribute_names, #attribute_present?, #attributes, #has_attribute?
Methods included from Callbacks
#destroy
#create_version, #has_versions?, #model_type, #restore_version, #versions
#base_path_for_resource=, #delete, #destroy, #destroy!, #destroyed?, #eradicate, #persisted?, #save, #save!, #update, #update!
Methods included from Streaming
#headers, #stream
Methods included from Attributes
#assign_attributes, #create_date, #digest, #dirty_size, #empty?, #has_content?, #mime_type, #modified_date, #original_name, #original_name=, #persisted_size, #size
Methods included from Common
#<=>, #==, #etag, #freeze, #frozen?, #ldp_source, #readonly!, #readonly?
Constructor Details
#initialize(identifier = nil) {|self| ... } ⇒ File
Returns a new instance of File.
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/active_fedora/file.rb', line 32
def initialize(identifier = nil, &_block)
identifier = identifier.delete(:id) if identifier.is_a? Hash
identifier = identifier.uri if identifier.respond_to? :uri
run_callbacks(:initialize) do
case identifier
when nil, ::RDF::URI
@ldp_source = build_ldp_resource_via_uri identifier
when String
id = ActiveFedora::Associations::IDComposite.new([identifier], translate_uri_to_id).first
@ldp_source = build_ldp_resource id
else
raise "The first argument to #{self} must be a Hash, String or RDF::URI. You provided a #{identifier.class}"
end
@attributes = {}.with_indifferent_access
@readonly = false
yield self if block_given?
end
end
|
Instance Method Details
#attribute_will_change!(attr) ⇒ Object
100
101
102
103
|
# File 'lib/active_fedora/file.rb', line 100
def attribute_will_change!(attr)
return super unless attr == 'content'
changed_attributes['content'] = true
end
|
#changed? ⇒ Boolean
128
129
130
|
# File 'lib/active_fedora/file.rb', line 128
def changed?
super || content_changed? || metadata_changed?
end
|
#check_fixity ⇒ Object
92
93
94
|
# File 'lib/active_fedora/file.rb', line 92
def check_fixity
FixityService.new(@ldp_source.subject).check
end
|
#content ⇒ Object
154
155
156
|
# File 'lib/active_fedora/file.rb', line 154
def content
local_or_remote_content(true)
end
|
#content=(string_or_io) ⇒ Object
149
150
151
152
|
# File 'lib/active_fedora/file.rb', line 149
def content=(string_or_io)
content_will_change! unless @content == string_or_io
@content = string_or_io
end
|
#content_changed? ⇒ Boolean
118
119
120
121
|
# File 'lib/active_fedora/file.rb', line 118
def content_changed?
return true if new_record? && !local_or_remote_content(false).blank?
local_or_remote_content(false) != @ds_content
end
|
#datastream_will_change! ⇒ Object
96
97
98
|
# File 'lib/active_fedora/file.rb', line 96
def datastream_will_change!
attribute_will_change! :profile
end
|
#described_by ⇒ Object
52
53
54
55
|
# File 'lib/active_fedora/file.rb', line 52
def described_by
raise "#{self} isn't persisted yet" if new_record?
links['describedby'].first
end
|
#exists! ⇒ Object
If we know the record to exist (parent has LDP:contains), we can avoid unnecessary HEAD requests
72
73
74
|
# File 'lib/active_fedora/file.rb', line 72
def exists!
@exists = true
end
|
#inspect ⇒ Object
132
133
134
|
# File 'lib/active_fedora/file.rb', line 132
def inspect
"#<#{self.class} uri=\"#{uri}\" >"
end
|
#ldp_connection ⇒ Object
57
58
59
|
# File 'lib/active_fedora/file.rb', line 57
def ldp_connection
ActiveFedora.fedora.connection
end
|
This method is abstract.
Override this in your concrete datastream class.
Returns does this datastream contain metadata (not file data).
138
139
140
|
# File 'lib/active_fedora/file.rb', line 138
def metadata?
false
end
|
123
124
125
126
|
# File 'lib/active_fedora/file.rb', line 123
def metadata_changed?
return false if new_record? || links['describedby'].blank?
metadata.changed?
end
|
#new_record? ⇒ Boolean
If this file has a parent with ldp#contains, we know it is not new. By tracking exists we prevent an unnecessary HEAD request.
63
64
65
|
# File 'lib/active_fedora/file.rb', line 63
def new_record?
!@exists && ldp_source.new?
end
|
#refresh ⇒ Object
82
83
84
85
86
87
88
89
90
|
# File 'lib/active_fedora/file.rb', line 82
def refresh
@ldp_source = build_ldp_resource_via_uri(uri)
@original_name = nil
@mime_type = nil
@content = nil
@metadata = nil
@ds_content = nil
changed_attributes.clear
end
|
#reload ⇒ Object
When restoring from previous versions, we need to reload certain attributes from Fedora
77
78
79
80
|
# File 'lib/active_fedora/file.rb', line 77
def reload
return if new_record?
refresh
end
|
#remote_content ⇒ Object
105
106
107
108
|
# File 'lib/active_fedora/file.rb', line 105
def remote_content
return if new_record?
@ds_content ||= retrieve_content
end
|
#serialize! ⇒ Object
serializes any changed data into the content field
143
|
# File 'lib/active_fedora/file.rb', line 143
def serialize!; end
|
#to_solr(solr_doc = {}, _opts = {}) ⇒ Object
145
146
147
|
# File 'lib/active_fedora/file.rb', line 145
def to_solr(solr_doc = {}, _opts = {})
solr_doc
end
|
#uri=(uri) ⇒ Object
67
68
69
|
# File 'lib/active_fedora/file.rb', line 67
def uri=(uri)
@ldp_source = build_ldp_resource_via_uri(uri)
end
|