forked from samvera/rubydora
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f4e7961
Showing
16 changed files
with
793 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# rcov generated | ||
coverage | ||
|
||
# rdoc generated | ||
rdoc | ||
|
||
# yard generated | ||
doc | ||
.yardoc | ||
|
||
# bundler | ||
.bundle | ||
|
||
# jeweler generated | ||
pkg | ||
|
||
Gemfile.lock | ||
.rvmrc | ||
|
||
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: | ||
# | ||
# * Create a file at ~/.gitignore | ||
# * Include files you want ignored | ||
# * Run: git config --global core.excludesfile ~/.gitignore | ||
# | ||
# After doing this, these files will be ignored in all your git projects, | ||
# saving you from having to 'pollute' every project you touch with them | ||
# | ||
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line) | ||
# | ||
# For MacOS: | ||
# | ||
#.DS_Store | ||
# | ||
# For TextMate | ||
#*.tmproj | ||
#tmtags | ||
# | ||
# For emacs: | ||
#*~ | ||
#\#* | ||
#.\#* | ||
# | ||
# For vim: | ||
*.swp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
source "http://rubygems.org" | ||
|
||
gem "fastercsv" | ||
gem "rest-client" | ||
gem "nokogiri" | ||
|
||
# Add dependencies required to use your gem here. | ||
# Example: | ||
# gem "activesupport", ">= 2.3.5" | ||
|
||
# Add dependencies to develop your gem here. | ||
# Include everything needed to run rake, tests, features, etc. | ||
group :development do | ||
gem "shoulda", ">= 0" | ||
gem "bundler", "~> 1.0.0" | ||
gem "jeweler", "~> 1.5.1" | ||
gem "rcov", ">= 0" | ||
gem "rspec" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2010 Chris Beer | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
= rubydora | ||
|
||
Description goes here. | ||
|
||
== Contributing to rubydora | ||
|
||
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet | ||
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it | ||
* Fork the project | ||
* Start a feature/bugfix branch | ||
* Commit and push until you are happy with your contribution | ||
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. | ||
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it. | ||
|
||
== Copyright | ||
|
||
Copyright (c) 2011 Chris Beer. See LICENSE.txt for | ||
further details. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require 'rubygems' | ||
require 'bundler' | ||
begin | ||
Bundler.setup(:default, :development) | ||
rescue Bundler::BundlerError => e | ||
$stderr.puts e.message | ||
$stderr.puts "Run `bundle install` to install missing gems" | ||
exit e.status_code | ||
end | ||
require 'rake' | ||
|
||
require 'jeweler' | ||
Jeweler::Tasks.new do |gem| | ||
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options | ||
gem.name = "rubydora" | ||
gem.homepage = "http://github.com/cbeer/rubydora" | ||
gem.license = "MIT" | ||
gem.summary = %Q{TODO: one-line summary of your gem} | ||
gem.description = %Q{TODO: longer description of your gem} | ||
gem.email = "chris@cbeer.info" | ||
gem.authors = ["Chris Beer"] | ||
end | ||
Jeweler::RubygemsDotOrgTasks.new | ||
|
||
# Get your spec rake tasks working in RSpec 2.0 | ||
|
||
require 'rspec/core/rake_task' | ||
|
||
desc 'Default: run specs.' | ||
task :default => :spec | ||
|
||
desc "Run specs" | ||
RSpec::Core::RakeTask.new do |t| | ||
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default. | ||
# Put spec opts in a file named .rspec in root | ||
end | ||
|
||
desc "Generate code coverage" | ||
require "rcov/rcovtask" | ||
RSpec::Core::RakeTask.new(:coverage) do |t| | ||
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default. | ||
t.rcov = true | ||
t.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems/*'] | ||
end | ||
|
||
require 'rake/rdoctask' | ||
Rake::RDocTask.new do |rdoc| | ||
version = File.exist?('VERSION') ? File.read('VERSION') : "" | ||
|
||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = "rubydora #{version}" | ||
rdoc.rdoc_files.include('README*') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Rubydora | ||
autoload :Datastream, "rubydora/datastream" | ||
autoload :Repository, "rubydora/repository" | ||
autoload :ResourceIndex, "rubydora/resource_index" | ||
autoload :RestApiClient, "rubydora/rest_api_client" | ||
autoload :DigitalObject, "rubydora/digital_object" | ||
|
||
require 'fastercsv' | ||
require 'restclient' | ||
require 'nokogiri' | ||
|
||
def self.version | ||
@version ||= File.read(File.join(File.dirname(__FILE__), '..', 'VERSION')).chomp | ||
end | ||
|
||
VERSION = self.version | ||
|
||
def self.connect *args | ||
Repository.new *args | ||
end | ||
|
||
def self.repository | ||
nil | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module Rubydora | ||
module Datastream | ||
def self.new digital_object, dsid, dsxml = nil | ||
ds = Base.new digital_object, dsid | ||
ds.profile = dsxml | ||
ds | ||
end | ||
|
||
class Base | ||
attr_reader :dsid | ||
|
||
def initialize digital_object, dsid | ||
@digital_object = digital_object | ||
@dsid = dsid | ||
end | ||
|
||
def new! | ||
@new = true | ||
end | ||
|
||
def new? | ||
@new | ||
end | ||
|
||
|
||
def profile | ||
@profile ||= begin | ||
profile = nil | ||
end | ||
end | ||
|
||
def profile= xml | ||
@profile = xml | ||
end | ||
|
||
def dirty? | ||
false | ||
end | ||
|
||
def save | ||
return create if new? | ||
end | ||
|
||
protected | ||
|
||
def client | ||
@digital_object.send(:client)["datastreams/%s"%[dsid]] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
module Rubydora | ||
module DigitalObject | ||
def self.find pid, repository = nil | ||
Base.new pid, repository | ||
end | ||
|
||
def self.create pid, options = {}, repository = nil | ||
repository ||= Rubydora.repository | ||
|
||
repository.ingest(options.merge(:pid => pid)) | ||
|
||
Base.new pid, repository | ||
end | ||
|
||
class Base | ||
attr_reader :pid | ||
|
||
def initialize pid, repository = nil | ||
@pid = pid | ||
@repository = repository | ||
end | ||
|
||
def delete | ||
repository.purge_object(:pid => pid) | ||
end | ||
|
||
def profile | ||
@profile ||= begin | ||
profile_xml = repository.object(:pid => pid) | ||
profile_xml.gsub! '<objectProfile', '<objectProfile xmlns="http://www.fedora.info/definitions/1/0/access/"' unless profile_xml =~ /xmlns=/ | ||
doc = Nokogiri::XML(profile_xml) | ||
h = doc.xpath('/access:objectProfile/*', {'access' => "http://www.fedora.info/definitions/1/0/access/"} ).inject({}) do |sum, node| | ||
sum[node.name] ||= [] | ||
sum[node.name] << node.text | ||
|
||
if node.name == "objModels" | ||
sum[node.name] = node.xpath('access:model', {'access' => "http://www.fedora.info/definitions/1/0/access/"}).map { |x| x.text } | ||
end | ||
|
||
sum | ||
end | ||
h.select { |key, value| value.length == 1 }.each do |key, value| | ||
h[key] = value.first | ||
end | ||
|
||
h | ||
|
||
end | ||
end | ||
|
||
def datastreams | ||
@datastreams ||= begin | ||
h = Hash.new { |h,k| h[k] = Datastream.new self, k; h[k].new!; h[k] } | ||
datastreams_xml = repository.datastreams(:pid => pid) | ||
datastreams_xml.gsub! '<objectDatastreams', '<objectDatastreams xmlns="http://www.fedora.info/definitions/1/0/access/"' unless datastreams_xml =~ /xmlns=/ | ||
doc = Nokogiri::XML(datastreams_xml) | ||
doc.xpath('//access:datastream', {'access' => "http://www.fedora.info/definitions/1/0/access/"}).each { |ds| h[ds['dsid']] = Datastream.new self, ds['dsid'], ds.to_s } | ||
h | ||
end | ||
end | ||
|
||
def save | ||
self.datastreams.select(&:dirty?).reject(&:empty?).each(&:save) | ||
end | ||
|
||
|
||
protected | ||
|
||
def repository | ||
@repository ||= Rubydora.repository | ||
end | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Rubydora | ||
class Repository | ||
include ResourceIndex | ||
include RestApiClient | ||
attr_reader :config | ||
|
||
def initialize options = {} | ||
@config = options | ||
end | ||
|
||
def find pid | ||
DigitalObject.find(pid, self) | ||
end | ||
|
||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Rubydora | ||
module ResourceIndex | ||
def find_by_sparql query, options = { :binding => 'pid' } | ||
self.sparql(query).map { |x| self.find(x[options[:binding]]) rescue nil } | ||
end | ||
|
||
def sparql query | ||
FasterCSV.parse(self.risearch(query), :headers => true) | ||
end | ||
|
||
protected | ||
def risearch query, options = {} | ||
request_params = { :dt => 'on', :format => 'CSV', :lang => 'sparql', :limit => nil, :query => query, type => 'tuples' }.merge(options) | ||
|
||
self.client['risearch'].post request_params | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.