Method: ActiveFedora::Core#initialize

Defined in:
lib/active_fedora/core.rb

#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.

Yields:

  • (_self)

Yield Parameters:

Raises:



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