lib/ezid/identifier.rb in ezid-client-1.1.1 vs lib/ezid/identifier.rb in ezid-client-1.2.0
- old
+ new
@@ -34,11 +34,11 @@
# Retrieves an identifier
# @return [Ezid::Identifier] the identifier
# @raise [Ezid::Error] if the identifier does not exist in EZID
def find(id)
identifier = new(id: id)
- identifier.reload
+ identifier.load_metadata
end
end
self.defaults = {}
@@ -63,14 +63,14 @@
def to_s
id
end
# Returns the identifier metadata
- # @param refresh [Boolean] - flag to refresh the metadata from EZID if stale (default: `true`)
+ # @param load [Boolean] - flag to load the metadata from EZID if stale (default: `true`)
# @return [Ezid::Metadata] the metadata
- def metadata(refresh = true)
- refresh_metadata if refresh && stale?
+ def metadata(load = true)
+ load_metadata if load && stale?
@metadata
end
# Persist the identifer and/or metadata to EZID.
# If the identifier is already persisted, this is an update operation;
@@ -112,15 +112,23 @@
def update(data={})
update_metadata(data)
save
end
- # Reloads the metadata from EZID (local changes will be lost!)
+ # @deprecated Use {#load_metadata} instead.
+ def reload
+ warn "[DEPRECATION] `reload` is deprecated and will be removed in version 2.0. Use `load_metadata` instead."
+ load_metadata
+ end
+
+ # Loads the metadata from EZID (local changes will be lost!)
# @return [Ezid::Identifier] the identifier
# @raise [Ezid::Error]
- def reload
- refresh_metadata
+ def load_metadata
+ response = client.get_identifier_metadata(id)
+ self.metadata = Metadata.new(response.metadata)
+ self.state = :persisted
self
end
# Empties the (local) metadata (changes will be lost!)
# @return [Ezid::Identifier] the identifier
@@ -163,14 +171,19 @@
def deletable?
persisted? && reserved?
end
# Mark the identifier as unavailable
- # @param reason [String] an optional reason
+ # @param reason [String] an optional reason
# @return [String] the new status
def unavailable!(reason = nil)
- raise Error, "Cannot make a reserved identifier unavailable." if persisted? && reserved?
+ if persisted? && reserved?
+ raise Error, "Cannot make a reserved identifier unavailable."
+ end
+ if unavailable? and reason.nil?
+ return
+ end
value = UNAVAILABLE
if reason
value += " | #{reason}"
end
self.status = value
@@ -192,15 +205,9 @@
private
def stale?
persisted? && metadata(false).empty?
- end
-
- def refresh_metadata
- response = client.get_identifier_metadata(id)
- self.metadata = Metadata.new response.metadata
- self.state = :persisted
end
def clear_metadata
metadata(false).clear
end