module ActiveFedora::Core
def assert_content_model
def assert_content_model self.has_model = self.class.to_rdf_representation end
def build_ldp_resource(id = nil)
def build_ldp_resource(id = nil) ActiveFedora.fedora.ldp_resource_service.build(self.class, id) end
def check_persistence
def check_persistence raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that has been destroyed" if destroyed? raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that hasn't been saved" end
def freeze
def freeze @resource.freeze # @attributes = @attributes.clone.freeze attached_files.freeze self end
def init_internals
def init_internals @resource = nil @readonly = false @association_cache = {} end
def init_with_resource(rdf_resource)
post.init_with_resource(Ldp::Resource.new('http://example.com/post/1'))
post = Post.allocate
end
class Post < ActiveFedora::Base
example:
Initialize an empty model object and set its +resource+
def init_with_resource(rdf_resource) init_internals @ldp_source = rdf_resource load_attached_files run_callbacks :find run_callbacks :initialize self end
def initialize(attributes = nil, &_block)
+:namespace+ value to Fedora::Repository.nextid to generate the next id available within
Also, if +attrs+ does not contain +:id+ but does contain +:namespace+ it will pass the
next available Fedora id, and mark as new object.
Constructor. You may supply a custom +:id+, or we call the Fedora Rest API for the
def initialize(attributes = nil, &_block) init_internals attributes = attributes.dup if attributes # can't dup nil in Ruby 2.3 id = attributes && (attributes.delete(:id) || attributes.delete('id')) @ldp_source = build_ldp_resource(id) raise IllegalOperation, "Attempting to recreate existing ldp_source: `#{ldp_source.subject}'" unless ldp_source.new? assign_attributes(attributes) if attributes assert_content_model load_attached_files yield self if block_given? _run_initialize_callbacks end
def inspect
def inspect inspection = ["id: #{id.inspect}"] inspection += self.class.attribute_names.collect do |name| "#{name}: #{attribute_for_inspect(name)}" if has_attribute?(name) end "#<#{self.class} #{inspection.compact.join(', ')}>" end
def logger
def logger self.class.logger end
def reload
def reload check_persistence unless persisted? clear_association_cache clear_attached_files refresh load_attached_files self rescue Ldp::Gone => err logger.error("Tried to reload an object that has been destroyed.\n\t#{err.message}") raise ActiveFedora::ObjectNotFoundError end
def uri=(uri)
- Note: - This can only be run on an unpersisted resource.
Parameters:
-
uri
(#to_s
) -- a full fedora URI or relative ID to set this resource
def uri=(uri) raise AlreadyPersistedError, "You can not set a URI for a persisted ActiveFedora object." if persisted? @ldp_source = build_ldp_resource(self.class.uri_to_id(uri)) end