module ActiveFedora::Core
def self.translate_id_to_uri=(translator)
def self.translate_id_to_uri=(translator) @@translate_id_to_uri = translator || FedoraIdTranslator end
def self.translate_uri_to_id=(translator)
def self.translate_uri_to_id=(translator) @@translate_uri_to_id = translator || FedoraUriTranslator end
def ==(comparison_object)
def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object.id == id && !comparison_object.new_record?) end
def assert_content_model
This can be overriden to assert a different model
def assert_content_model self.has_model = self.class.to_s 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 if destroyed? raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that has been destroyed" else raise ActiveFedora::ObjectNotFoundError, "Can't reload an object that hasn't been saved" end end
def freeze
def freeze @resource.freeze #@attributes = @attributes.clone.freeze attached_files.freeze self end
def frozen?
def frozen? attached_files.frozen? 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_or_id = 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_or_id = nil, &block) init_internals attributes = initialize_attributes(attributes_or_id) @ldp_source = build_ldp_resource(attributes.delete(:id)) raise IllegalOperation, "Attempting to recreate existing ldp_source: `#{ldp_source.subject}'" unless ldp_source.new? assert_content_model load_attached_files self.attributes = attributes yield self if block_given? run_callbacks :initialize end
def initialize_attributes attributes_or_id
def initialize_attributes attributes_or_id case attributes_or_id when String attributes = {id: attributes_or_id}.with_indifferent_access when Hash attributes = attributes_or_id.with_indifferent_access # TODO: Remove when we decide using 'pid' is no longer supported. if !attributes.key?(:id) && attributes.key?(:pid) Deprecation.warn Core, 'Initializing with :pid is deprecated and will be removed in active-fedora 10.0. Use :id instead' attributes[:id] = attributes.delete(:pid) end when NilClass attributes = {}.with_indifferent_access else raise ArgumentError, "#{attributes_or_id.class} is not acceptable" end return attributes end
def ldp_source
def ldp_source @ldp_source end
def readonly!
def readonly! @readonly = true end
def readonly?
Returns +true+ if the record is read only. Records loaded through joins with piggy-back
def readonly? @readonly end
def reload
def reload check_persistence unless persisted? clear_association_cache clear_attached_files refresh load_attached_files self end