Module: ActiveFedora::Core
- Extended by:
 - ActiveSupport::Autoload, ActiveSupport::Concern
 
- Includes:
 - Common
 
- 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
- #freeze ⇒ Object
 - 
  
    
      #init_with_resource(rdf_resource)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Initialize an empty model object and set its
resourceexample:. - 
  
    
      #initialize(attributes = nil) {|_self| ... } ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Constructor.
 - 
  
    
      #inspect  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Returns the contents of the record as a nicely formatted string.
 - 
  
    
      #reload  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Reloads the object from Fedora.
 - #uri=(uri) ⇒ Object
 
Methods included from Common
#<=>, #==, #etag, #frozen?, #ldp_source, #readonly!, #readonly?
Instance Method Details
#freeze ⇒ Object
      86 87 88 89 90 91  | 
    
      # File 'lib/active_fedora/core.rb', line 86 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'
  
      77 78 79 80 81 82 83 84  | 
    
      # File 'lib/active_fedora/core.rb', line 77 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 = 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.
      31 32 33 34 35 36 37 38 39 40 41 42 43  | 
    
      # File 'lib/active_fedora/core.rb', line 31 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  | 
  
#inspect ⇒ Object
Returns the contents of the record as a nicely formatted string.
      96 97 98 99 100 101 102 103  | 
    
      # File 'lib/active_fedora/core.rb', line 96 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  | 
  
#reload ⇒ Object
Reloads the object from Fedora.
      56 57 58 59 60 61 62 63 64 65 66  | 
    
      # File 'lib/active_fedora/core.rb', line 56 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.}") raise ActiveFedora::ObjectNotFoundError end  | 
  
#uri=(uri) ⇒ Object
This can only be run on an unpersisted resource.
      49 50 51 52 53  | 
    
      # File 'lib/active_fedora/core.rb', line 49 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  |