Module: ActiveFedora::Core
- Extended by:
- ActiveSupport::Autoload, ActiveSupport::Concern
- Included in:
- Base
- Defined in:
- lib/active_fedora/core.rb,
lib/active_fedora/core/fedora_id_translator.rb,
lib/active_fedora/core/fedora_uri_translator.rb
Defined Under Namespace
Modules: ClassMethods Classes: FedoraIdTranslator, FedoraUriTranslator
Instance Method Summary collapse
- #==(other) ⇒ Object
- #freeze ⇒ Object
-
#init_with_resource(rdf_resource) ⇒ Object
Initialize an empty model object and set its
resource
example:. -
#initialize(attributes_or_id = nil) {|_self| ... } ⇒ Object
Constructor.
- #ldp_source ⇒ Object
-
#readonly! ⇒ Object
Marks this record as read only.
-
#readonly? ⇒ Boolean
Returns
true
if the record is read only. -
#reload ⇒ Object
Reloads the object from Fedora.
- #uri=(uri) ⇒ Object
Instance Method Details
#==(other) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/active_fedora/core.rb', line 80 def ==(other) other.equal?(self) || (other.instance_of?(self.class) && other.id == id && !other.new_record?) end |
#freeze ⇒ Object
87 88 89 90 91 92 |
# File 'lib/active_fedora/core.rb', line 87 def freeze @resource.freeze # @attributes = @attributes.clone.freeze attached_files.freeze self 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'
71 72 73 74 75 76 77 78 |
# File 'lib/active_fedora/core.rb', line 71 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_id = 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.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/active_fedora/core.rb', line 27 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 |
#ldp_source ⇒ Object
18 19 20 |
# File 'lib/active_fedora/core.rb', line 18 def ldp_source @ldp_source end |
#readonly! ⇒ Object
Marks this record as read only.
103 104 105 |
# File 'lib/active_fedora/core.rb', line 103 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.
98 99 100 |
# File 'lib/active_fedora/core.rb', line 98 def readonly? @readonly end |
#reload ⇒ Object
Reloads the object from Fedora.
53 54 55 56 57 58 59 60 |
# File 'lib/active_fedora/core.rb', line 53 def reload check_persistence unless persisted? clear_association_cache clear_attached_files refresh load_attached_files self end |
#uri=(uri) ⇒ Object
This can only be run on an unpersisted resource.
44 45 46 47 48 49 50 |
# File 'lib/active_fedora/core.rb', line 44 def uri=(uri) if persisted? raise AlreadyPersistedError, "You can not set a URI for a persisted ActiveFedora object." else @ldp_source = build_ldp_resource(self.class.uri_to_id(uri)) end end |