Class: Rubydora::Repository
- Inherits:
-
Object
- Object
- Rubydora::Repository
- Includes:
- ResourceIndex, RestApiClient
- Defined in:
- lib/rubydora/repository.rb
Overview
Fedora Repository object that provides API access
Constant Summary
Constants included from RestApiClient
Rubydora::RestApiClient::API_DOCUMENTATION
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
repository configuration (see #initialize).
Instance Method Summary collapse
-
#create(pid, options = {}) ⇒ Object
create a new fedora object (see also DigitalObject#save)
-
#find(pid) ⇒ Object
find an existing fedora object TODO: raise an error if the object does not yet exist
-
#initialize(options = {}) ⇒ Repository
constructor
A new instance of Repository.
-
#ping ⇒ Object
Raise an error if unable to connect to the API endpoint.
-
#profile ⇒ Hash
repository profile (from API-A-LITE data).
-
#version ⇒ Float
Repository version.
Methods included from RestApiClient
#add_datastream, #add_relationship, #client, #datastream, #datastream_dissemination, #datastream_url, #datastream_versions, #dissemination, #dissemination_url, #find_objects, #ingest, #modify_datastream, #modify_object, #next_pid, #object, #object_url, #object_versions, #object_xml, #purge_datastream, #purge_object, #purge_relationship, #relationships, #set_datastream_options, #url_for
Methods included from ResourceIndex
#find_by_sparql, #find_by_sparql_relationship, #sparql
Constructor Details
#initialize(options = {}) ⇒ Repository
Returns a new instance of Repository.
14 15 16 17 |
# File 'lib/rubydora/repository.rb', line 14 def initialize = {} @config = load_api_abstraction end |
Instance Attribute Details
#config ⇒ Object (readonly)
repository configuration (see #initialize)
8 9 10 |
# File 'lib/rubydora/repository.rb', line 8 def config @config end |
Instance Method Details
#create(pid, options = {}) ⇒ Object
create a new fedora object (see also DigitalObject#save)
25 26 27 |
# File 'lib/rubydora/repository.rb', line 25 def create pid, = {} DigitalObject.create(pid, = {}, self) end |
#find(pid) ⇒ Object
find an existing fedora object TODO: raise an error if the object does not yet exist
20 21 22 |
# File 'lib/rubydora/repository.rb', line 20 def find pid DigitalObject.find(pid, self) end |
#ping ⇒ Object
Raise an error if unable to connect to the API endpoint
64 65 66 67 |
# File 'lib/rubydora/repository.rb', line 64 def ping raise "Unable to establish connection to Fedora Repository" unless profile true end |
#profile ⇒ Hash
repository profile (from API-A-LITE data)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rubydora/repository.rb', line 31 def profile @profile ||= begin profile_xml = client['describe?xml=true'].get profile_xml.gsub! '<fedoraRepository', '<fedoraRepository xmlns="http://www.fedora.info/definitions/1/0/access/"' unless profile_xml =~ /xmlns=/ doc = Nokogiri::XML(profile_xml) xmlns = { 'access' => "http://www.fedora.info/definitions/1/0/access/" } h = doc.xpath('/access:fedoraRepository/*', xmlns).inject({}) do |sum, node| sum[node.name] ||= [] case node.name when "repositoryPID" sum[node.name] << Hash[*node.xpath('access:*', xmlns).map { |x| [node.name, node.text]}.flatten] else sum[node.name] << node.text end sum end h.select { |key, value| value.length == 1 }.each do |key, value| next if key == "objModels" h[key] = value.first end h rescue nil end end |
#version ⇒ Float
Returns repository version.
59 60 61 |
# File 'lib/rubydora/repository.rb', line 59 def version @version ||= profile['repositoryVersion'].to_f rescue nil end |