class Ezid::Record
Attributes
identifier[R]
metadata[R]
Public Class Methods
new(session, identifier, metadata = {}, persisted = false)
click to toggle source
# File lib/ezid/record.rb, line 5 def initialize(session, identifier, metadata = {}, persisted = false) @identifier = identifier @metadata = metadata @session = session @changed = [] @stale = false @persisted = persisted self end
Public Instance Methods
[](attribute)
click to toggle source
# File lib/ezid/record.rb, line 30 def [](attribute) @metadata[attribute] end
[]=(attribute, value)
click to toggle source
# File lib/ezid/record.rb, line 34 def []=(attribute, value) if @metadata[attribute] != value @changed << attribute @changed.uniq! end @metadata[attribute] = value end
delete()
click to toggle source
# File lib/ezid/record.rb, line 42 def delete @session.delete(identifier) end
make_public()
click to toggle source
Utility Methods
# File lib/ezid/record.rb, line 63 def make_public self['_status'] = Ezid::ApiSession::PUBLIC end
persisted?()
click to toggle source
# File lib/ezid/record.rb, line 26 def persisted? @changed.length != 0 ? false : @persisted end
profile()
click to toggle source
# File lib/ezid/record.rb, line 84 def profile self['_profile'] end
profile=(value)
click to toggle source
# File lib/ezid/record.rb, line 88 def profile=(value) self['_profile'] = value end
reload()
click to toggle source
There has to be a better way to do this.
# File lib/ezid/record.rb, line 16 def reload if self.stale? new_record = @session.get(@identifier) @identifier = new_record.identifier @metadata = new_record.metadata @stale = false end self end
save()
click to toggle source
# File lib/ezid/record.rb, line 46 def save return self if self.persisted? modify_data = @changed.each_with_object({ }) { |key, hash| hash[key] = @metadata[key] } request_uri = "/id/#{@identifier}" result = @session.send(:call_api, request_uri, :post, modify_data) raise "Unable to save - error: #{result.response}" if result.errored? @persisted = true @stale = true @changed = [] self end
stale?()
click to toggle source
# File lib/ezid/record.rb, line 58 def stale? @stale end
status()
click to toggle source
Shortcut methods - leave behind from old implementation.
# File lib/ezid/record.rb, line 72 def status self['_status'] end
target()
click to toggle source
# File lib/ezid/record.rb, line 76 def target self['_target'] end
target=(value)
click to toggle source
# File lib/ezid/record.rb, line 80 def target=(value) self['_target'] = value end