lib/active_fedora/base.rb in active-fedora-6.2.0 vs lib/active_fedora/base.rb in active-fedora-6.3.0
- old
+ new
@@ -28,12 +28,11 @@
class_attribute :fedora_connection, :profile_solr_name
self.fedora_connection = {}
self.profile_solr_name = ActiveFedora::SolrService.solr_name("object_profile", :displayable)
- delegate :label, :label=, to: :inner_object
- delegate :state=, :state, to: :inner_object
+ delegate :state=,:label=, to: :inner_object
def method_missing(name, *args)
dsid = corresponding_datastream_name(name)
if dsid
### Create and invoke a proxy method
@@ -62,10 +61,23 @@
def persisted?
!new_object?
end
+ def mark_for_destruction
+ @marked_for_destruction = true
+ end
+
+ def marked_for_destruction?
+ @marked_for_destruction
+ end
+
+ def reload(options = nil)
+ @marked_for_destruction = false
+ super
+ end
+
# Constructor. You may supply a custom +:pid+, or we call the Fedora Rest API for the
# next available Fedora pid, and mark as new object.
# Also, if +attrs+ does not contain +:pid+ but does contain +:namespace+ it will pass the
# +:namespace+ value to Fedora::Repository.nextid to generate the next pid available within
# the given namespace.
@@ -182,13 +194,11 @@
credentials = ActiveFedora.config.credentials[0]
else
credentials = ActiveFedora.config.credentials
end
fedora_connection[0] ||= ActiveFedora::RubydoraConnection.new(credentials)
- d = Nokogiri::XML( fedora_connection[0].connection.next_pid(args))
- pid = d.xpath('//fedora:pid', 'fedora' => 'http://www.fedora.info/definitions/1/0/management/').text
- pid
+ fedora_connection[0].connection.mint(args)
end
def inner_object # :nodoc
@inner_object
end
@@ -218,24 +228,38 @@
"info:fedora/#{pid}"
end
#return the owner id
def owner_id
- @inner_object.ownerId
+ Array(@inner_object.ownerId).first
end
def owner_id=(owner_id)
@inner_object.ownerId=(owner_id)
end
+ def label
+ Array(@inner_object.label).first
+ end
+
+ def state
+ Array(@inner_object.state).first
+ end
+
#return the create_date of the inner object (unless it's a new object)
def create_date
- @inner_object.new? ? Time.now : @inner_object.profile["objCreateDate"]
+ if @inner_object.new?
+ Time.now
+ elsif @inner_object.respond_to? :createdDate
+ Array(@inner_object.createdDate).first
+ else
+ @inner_object.profile['objCreateDate']
+ end
end
#return the modification date of the inner object (unless it's a new object)
def modified_date
- @inner_object.new? ? Time.now : @inner_object.profile["objLastModDate"]
+ @inner_object.new? ? Time.now : Array(@inner_object.lastModifiedDate).first
end
def ==(comparison_object)
comparison_object.equal?(self) ||
(comparison_object.instance_of?(self.class) &&