Module: ActiveFedora::Core
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #==(comparison_object) ⇒ Object
- #freeze ⇒ Object
- #frozen? ⇒ Boolean
-
#init_with_resource(rdf_resource) ⇒ Object
Initialize an empty model object and set its
resourceexample:. -
#initialize(attributes_or_resource_or_url = nil) {|_self| ... } ⇒ Object
Constructor.
- #ldp_source ⇒ Object
-
#readonly! ⇒ Object
Marks this record as read only.
-
#readonly? ⇒ Boolean
Returns
trueif the record is read only. -
#reload ⇒ Object
Reloads the object from Fedora.
Instance Method Details
#==(comparison_object) ⇒ Object
76 77 78 79 80 81 |
# File 'lib/active_fedora/core.rb', line 76 def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object.id == id && !comparison_object.new_record?) end |
#freeze ⇒ Object
83 84 85 86 87 88 |
# File 'lib/active_fedora/core.rb', line 83 def freeze @resource.freeze #@attributes = @attributes.clone.freeze attached_files.freeze self end |
#frozen? ⇒ Boolean
90 91 92 |
# File 'lib/active_fedora/core.rb', line 90 def frozen? attached_files.frozen? end |
#init_with_resource(rdf_resource) ⇒ Object
Initialize an empty model object and set its resource example:
class Post < ActiveFedora::Base
end
post = Post.allocate
post.init_with_resource(Ldp::Resource.new('http://example.com/post/1'))
post.title # => 'hello world'
67 68 69 70 71 72 73 74 |
# File 'lib/active_fedora/core.rb', line 67 def init_with_resource(rdf_resource) init_internals @ldp_source = rdf_resource load_attached_files run_callbacks :find run_callbacks :initialize self end |
#initialize(attributes_or_resource_or_url = nil) {|_self| ... } ⇒ Object
Constructor. You may supply a custom :id, or we call the Fedora Rest API for the next available Fedora id, and mark as new object. Also, if attrs does not contain :id but does contain :namespace it will pass the :namespace value to Fedora::Repository.nextid to generate the next id available within the given namespace.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/active_fedora/core.rb', line 36 def initialize(attributes_or_resource_or_url = nil, &block) init_internals attributes = initialize_resource_and_attributes(attributes_or_resource_or_url) raise IllegalOperation, "Attempting to recreate existing ldp_source: `#{ldp_source.subject}'" unless ldp_source.new? assert_content_model load_attached_files self.attributes = attributes if attributes yield self if block_given? run_callbacks :initialize end |
#ldp_source ⇒ Object
27 28 29 |
# File 'lib/active_fedora/core.rb', line 27 def ldp_source @ldp_source end |
#readonly! ⇒ Object
Marks this record as read only.
101 102 103 |
# File 'lib/active_fedora/core.rb', line 101 def readonly! @readonly = true end |
#readonly? ⇒ Boolean
Returns true if the record is read only. Records loaded through joins with piggy-back attributes will be marked as read only since they cannot be saved.
96 97 98 |
# File 'lib/active_fedora/core.rb', line 96 def readonly? @readonly end |
#reload ⇒ Object
Reloads the object from Fedora.
49 50 51 52 53 54 55 56 |
# File 'lib/active_fedora/core.rb', line 49 def reload check_persistence unless persisted? clear_association_cache clear_attached_files refresh load_attached_files self end |