active_fedora_finders 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.textile +29 -0
- data/Rakefile +19 -0
- data/active_fedora_finders.gemspec +37 -0
- data/lib/active_fedora_finders.rb +128 -0
- data/lib/active_fedora_finders/version.rb +5 -0
- data/lib/tasks/af_finders_dev.rake +37 -0
- data/spec/config_helper.rb +27 -0
- data/spec/finders_spec.rb +54 -0
- data/spec/fixtures/find_multiple.xml +10 -0
- data/spec/fixtures/find_none.xml +4 -0
- data/spec/fixtures/find_one.xml +7 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/mock_fedora.rb +45 -0
- metadata +232 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Benjamin Armintor
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
ActiveFedora::Finders
|
2
|
+
|
3
|
+
A mixin to allow use of dynamic finder methods (a la Rails) with ActiveFedora. These methods operate against the FCRepo Object Search.
|
4
|
+
Allowed fields are the 15 DCES metadata fields, and the FCRepo object properties, ie:
|
5
|
+
|
6
|
+
SINGLE_VALUE_FIELDS = [:pid, :cDate, :mDate, :label]
|
7
|
+
SYSTEM_FIELDS = SINGLE_VALUE_FIELDS.concat [:ownerId]
|
8
|
+
DC_FIELDS = [:contributor, :coverage, :creator, :date, :description, :format,
|
9
|
+
:identifier, :language, :publisher, :relation, :rights, :source,
|
10
|
+
:subject, :title, :type ]
|
11
|
+
SUPPORTED_ALTS = [:cdate, :create_date, :mdate, :modified_date, :owner_id]
|
12
|
+
|
13
|
+
|
14
|
+
Example:
|
15
|
+
|
16
|
+
class MyModel < ActiveFedora::Base
|
17
|
+
include ActiveFedora::Finders
|
18
|
+
end
|
19
|
+
|
20
|
+
obj = MyModel.find_by_identifier("fedora-system:ContentModel-3.0")
|
21
|
+
|
22
|
+
**
|
23
|
+
|
24
|
+
Roadmap:
|
25
|
+
|
26
|
+
0.1: dynamic finders, bang support
|
27
|
+
0.2: support or_create|initialize
|
28
|
+
0.3: support _all and _last
|
29
|
+
0.4: support scopes
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
require "bundler/setup"
|
5
|
+
require "active-fedora"
|
6
|
+
require "active_fedora_finders"
|
7
|
+
|
8
|
+
Bundler::GemHelper.install_tasks
|
9
|
+
|
10
|
+
# load rake tasks defined in lib/tasks that are not loaded in lib/active_fedora.rb
|
11
|
+
load "lib/tasks/af_finders_dev.rake" if defined?(Rake)
|
12
|
+
|
13
|
+
CLEAN.include %w[**/.DS_Store tmp *.log *.orig *.tmp **/*~]
|
14
|
+
|
15
|
+
task :spec => ['active_fedora_finders:rspec']
|
16
|
+
task :rcov => ['active_fedora_finders:rcov']
|
17
|
+
|
18
|
+
|
19
|
+
task :default => [:spec]
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "active_fedora_finders/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "active_fedora_finders"
|
7
|
+
s.version = ActiveFedora::Finders::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Benjamin Armintor"]
|
10
|
+
s.email = ["armintor@gmail.com"]
|
11
|
+
s.homepage = %q{https://github.com/barmintor/active_fedora_finders}
|
12
|
+
s.summary = %q{A library for adding ActiveRecord-style dynamic finders to ActiveFedora::Base subclasses.}
|
13
|
+
s.description = %q{A mixin library for ActiveFedora. Generates dynamic finder methods operating against the FCRepo object search terms (DCES elements and object properties).}
|
14
|
+
|
15
|
+
s.rubygems_version = %q{1.3.7}
|
16
|
+
|
17
|
+
s.add_dependency('active-fedora', '>=4.2.0')
|
18
|
+
s.add_dependency('nokogiri')
|
19
|
+
s.add_dependency("activerecord", '~>3.2.0')
|
20
|
+
s.add_dependency("activesupport", '~>3.2.0')
|
21
|
+
s.add_dependency("rubydora", '~>0.5.9')
|
22
|
+
s.add_development_dependency("yard")
|
23
|
+
s.add_development_dependency("RedCloth") # for RDoc formatting
|
24
|
+
s.add_development_dependency("rake")
|
25
|
+
s.add_development_dependency("rspec", ">= 2.9.0")
|
26
|
+
s.add_development_dependency("mocha", "0.10.5")
|
27
|
+
|
28
|
+
s.files = `git ls-files`.split("\n")
|
29
|
+
s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
|
30
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
31
|
+
s.extra_rdoc_files = [
|
32
|
+
"LICENSE.txt",
|
33
|
+
"README.textile"
|
34
|
+
]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'active-fedora'
|
2
|
+
require 'active_support'
|
3
|
+
require 'active_record'
|
4
|
+
require 'active_record/errors' # RecordNotFound is not autoloaded, and ActiveRecord::Base not referenced
|
5
|
+
module ActiveFedora
|
6
|
+
module Finders
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
extend ActiveSupport::Autoload
|
9
|
+
autoload :Version
|
10
|
+
|
11
|
+
SINGLE_VALUE_FIELDS = [:pid, :cDate, :mDate, :label]
|
12
|
+
SYSTEM_FIELDS = SINGLE_VALUE_FIELDS.concat [:ownerId]
|
13
|
+
DC_FIELDS = [:contributor, :coverage, :creator, :date, :description, :format,
|
14
|
+
:identifier, :language, :publisher, :relation, :rights, :source,
|
15
|
+
:subject, :title, :type ]
|
16
|
+
SUPPORTED_ALTS = [:cdate, :create_date, :mdate, :modified_date, :owner_id]
|
17
|
+
ALL_FIELDS = SYSTEM_FIELDS.concat(DC_FIELDS)
|
18
|
+
FIELD_KEYS = begin
|
19
|
+
fk = Hash[ALL_FIELDS.map {|a| [a.to_s, a]}]
|
20
|
+
fk["cdate"] = :cDate
|
21
|
+
fk["create_date"] = :cDate
|
22
|
+
fk["mdate"] = :mDate
|
23
|
+
fk["modified_date"] = :mDate
|
24
|
+
fk["owner_id"] = :ownerId
|
25
|
+
fk
|
26
|
+
end
|
27
|
+
|
28
|
+
included do
|
29
|
+
class << self
|
30
|
+
alias_method :active_fedora_find, :find
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module ClassMethods
|
35
|
+
def find(args)
|
36
|
+
if args.is_a? String
|
37
|
+
return active_fedora_find(args)
|
38
|
+
else
|
39
|
+
return find_by_conditions(nil, args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# modeled after ActiveRecord::FinderMethods.find_by_attributes
|
44
|
+
def find_by_attributes(match, attribute_names, *args)
|
45
|
+
conditions = Hash[attribute_names.map {|a| [a, args[attribute_names.index(a)]]}]
|
46
|
+
result = find_by_conditions(match, conditions)
|
47
|
+
if match.bang? && result.blank?
|
48
|
+
raise ActiveRecord::RecordNotFound, "Couldn't find #{self.name} with #{conditions.to_a.collect {|p| p.join(' = ')}.join(', ')}"
|
49
|
+
else
|
50
|
+
yield(result) if block_given?
|
51
|
+
result
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def find_by_conditions(match, args)
|
56
|
+
parms = args.dup
|
57
|
+
maxResults = (match.nil? or match.finder == :first) ? 1 : 25 # find_all and find_last not yet supported
|
58
|
+
query = ""
|
59
|
+
parms.each { |key, val|
|
60
|
+
if SINGLE_VALUE_FIELDS.include? key
|
61
|
+
query.concat "#{key.to_s}=#{val.to_s} "
|
62
|
+
else
|
63
|
+
query.concat "#{key.to_s}~#{val.to_s} "
|
64
|
+
end
|
65
|
+
}
|
66
|
+
query.strip!
|
67
|
+
results = []
|
68
|
+
if ActiveFedora.config.sharded?
|
69
|
+
(0...ActiveFedora.config.credentials.length).each {|ix|
|
70
|
+
ActiveFedora::Base.fedora_connection[ix] ||= ActiveFedora::RubydoraConnection.new(ActiveFedora.config.credentials[ix])
|
71
|
+
rubydora = ActiveFedora::Base.fedora_connection[ix].connection
|
72
|
+
if results.length <= maxResults
|
73
|
+
results.concat process_results(rubydora.find_objects(:query=>query,:pid=>'true', :maxResults=>maxResults))
|
74
|
+
end
|
75
|
+
}
|
76
|
+
else
|
77
|
+
ActiveFedora::Base.fedora_connection[0] ||= ActiveFedora::RubydoraConnection.new(ActiveFedora.config.credentials)
|
78
|
+
rubydora = ActiveFedora::Base.fedora_connection[0].connection
|
79
|
+
results.concat process_results(rubydora.find_objects(:query=>query,:pid=>'true', :maxResults=>maxResults))
|
80
|
+
end
|
81
|
+
return (maxResults == 1) ? results[0] : results
|
82
|
+
end
|
83
|
+
|
84
|
+
def process_results(results)
|
85
|
+
results = Nokogiri::XML.parse(results)
|
86
|
+
results = results.xpath('/f:result/f:resultList/f:objectFields/f:pid',{'f'=>"http://www.fedora.info/definitions/1/0/types/"})
|
87
|
+
results.collect { |result| active_fedora_find(result.text) }
|
88
|
+
end
|
89
|
+
|
90
|
+
# this method is patterned after an analog in ActiveRecord::DynamicMatchers
|
91
|
+
def all_attributes_exists?(attribute_names)
|
92
|
+
field_keys = attribute_names.map {|val| FIELD_KEYS[val] or val}
|
93
|
+
attribute_names.replace field_keys
|
94
|
+
attribute_names.reduce(true) {|result, att| ALL_FIELDS.include? att or SUPPORTED_ALTS.include? att}
|
95
|
+
end
|
96
|
+
|
97
|
+
# adapted from ActiveRecord::DynamicMatchers
|
98
|
+
def method_missing(method_id, *arguments, &block)
|
99
|
+
if match = (ActiveRecord::DynamicFinderMatch.match(method_id) || ActiveRecord::DynamicScopeMatch.match(method_id))
|
100
|
+
attribute_names = match.attribute_names
|
101
|
+
super unless all_attributes_exists?(attribute_names)
|
102
|
+
if !(match.is_a?(ActiveRecord::DynamicFinderMatch) && match.instantiator? && arguments.first.is_a?(Hash)) && arguments.size < attribute_names.size
|
103
|
+
method_trace = "#{__FILE__}:#{__LINE__}:in `#{method_id}'"
|
104
|
+
backtrace = [method_trace] + caller
|
105
|
+
raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{attribute_names.size})", backtrace
|
106
|
+
end
|
107
|
+
if match.respond_to?(:scope?) && match.scope?
|
108
|
+
self.class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
109
|
+
def self.#{method_id}(*args) # def self.scoped_by_user_name_and_password(*args)
|
110
|
+
attributes = Hash[[:#{attribute_names.join(',:')}].zip(args)] # attributes = Hash[[:user_name, :password].zip(args)]
|
111
|
+
#
|
112
|
+
scoped(:conditions => attributes) # scoped(:conditions => attributes)
|
113
|
+
end # end
|
114
|
+
METHOD
|
115
|
+
send(method_id, *arguments)
|
116
|
+
elsif match.finder?
|
117
|
+
find_by_attributes(match, attribute_names, *arguments, &block)
|
118
|
+
elsif match.instantiator?
|
119
|
+
find_or_instantiator_by_attributes(match, attribute_names, *arguments, &block)
|
120
|
+
end
|
121
|
+
else
|
122
|
+
super
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
APP_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../")
|
2
|
+
|
3
|
+
namespace :active_fedora_finders do
|
4
|
+
require 'active_fedora_finders'
|
5
|
+
|
6
|
+
# Use yard to build docs
|
7
|
+
begin
|
8
|
+
require 'yard'
|
9
|
+
require 'yard/rake/yardoc_task'
|
10
|
+
project_root = APP_ROOT
|
11
|
+
doc_destination = File.join(project_root, 'doc')
|
12
|
+
|
13
|
+
YARD::Rake::YardocTask.new(:doc) do |yt|
|
14
|
+
yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
|
15
|
+
[ File.join(project_root, 'README.textile')]
|
16
|
+
yt.options = ['--output-dir', doc_destination, '--readme', 'README.textile']
|
17
|
+
end
|
18
|
+
rescue LoadError
|
19
|
+
desc "Generate YARD Documentation"
|
20
|
+
task :doc do
|
21
|
+
abort "Please install the YARD gem to generate rdoc."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rspec/core/rake_task'
|
26
|
+
RSpec::Core::RakeTask.new(:rspec) do |spec|
|
27
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
28
|
+
spec.pattern += FileList['spec/*_spec.rb']
|
29
|
+
end
|
30
|
+
|
31
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
spec.pattern += FileList['spec/*_spec.rb']
|
34
|
+
spec.rcov = true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# copied directly from active-fedora
|
2
|
+
def mock_yaml(hash, path)
|
3
|
+
mock_file = mock(path.split("/")[-1])
|
4
|
+
File.stubs(:exist?).with(path).returns(true)
|
5
|
+
File.expects(:open).with(path).returns(mock_file)
|
6
|
+
YAML.expects(:load).returns(hash)
|
7
|
+
end
|
8
|
+
|
9
|
+
def default_predicate_mapping_file
|
10
|
+
File.expand_path(File.join(File.dirname(__FILE__),"..","config","predicate_mappings.yml"))
|
11
|
+
end
|
12
|
+
|
13
|
+
def stub_rails(opts={})
|
14
|
+
Object.const_set("Rails",Class)
|
15
|
+
Rails.send(:undef_method,:env) if Rails.respond_to?(:env)
|
16
|
+
Rails.send(:undef_method,:root) if Rails.respond_to?(:root)
|
17
|
+
opts.each { |k,v| Rails.send(:define_method,k){ return v } }
|
18
|
+
end
|
19
|
+
|
20
|
+
def unstub_rails
|
21
|
+
Object.send(:remove_const,:Rails) if defined?(Rails)
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup_pretest_env
|
25
|
+
ENV['RAILS_ENV']='test'
|
26
|
+
ENV['environment']='test'
|
27
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'config_helper'
|
3
|
+
|
4
|
+
describe ActiveFedora::Finders do
|
5
|
+
class TestBase < ActiveFedora::Base
|
6
|
+
include ActiveFedora::Finders
|
7
|
+
end
|
8
|
+
FCREPO_ID = 'fedora-system:ContentModel-3.0'
|
9
|
+
FCREPO_DATE = '2012-06-01T12:34:56.000Z'
|
10
|
+
|
11
|
+
describe "finder methods" do
|
12
|
+
describe "default find method" do
|
13
|
+
it "should call the normal find method when passed a string" do
|
14
|
+
TestBase.expects(:active_fedora_find).returns TestBase.new
|
15
|
+
TestBase.find(FCREPO_ID)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
describe "dynamic finder methods" do
|
19
|
+
it "should call .find_by_conditions with correct attributes" do
|
20
|
+
TestBase.expects(:find_by_conditions).with(is_a(ActiveRecord::DynamicFinderMatch), :identifier => FCREPO_ID).returns(TestBase.new)
|
21
|
+
TestBase.find_by_identifier(FCREPO_ID)
|
22
|
+
TestBase.expects(:find_by_conditions).with(is_a(ActiveRecord::DynamicFinderMatch), :cDate => FCREPO_DATE, :identifier => FCREPO_ID).returns(TestBase.new)
|
23
|
+
TestBase.find_by_create_date_and_identifier(FCREPO_DATE, FCREPO_ID)
|
24
|
+
end
|
25
|
+
it "should return an ActiveFedora::Base when there is a single result" do
|
26
|
+
stubfedora = mock("Fedora")
|
27
|
+
stubfedora.expects(:connection).returns(mock("Connection", :find_objects =>fixture('find_one.xml')))
|
28
|
+
TestBase.expects(:active_fedora_find).with(FCREPO_ID).returns TestBase.new(:pid=>FCREPO_ID)
|
29
|
+
ActiveFedora::Base.fedora_connection = [stubfedora]
|
30
|
+
TestBase.find_by_identifier(FCREPO_ID).should be_a TestBase
|
31
|
+
end
|
32
|
+
it "should return an array when there are multiple results" do
|
33
|
+
stubfedora = mock("Fedora")
|
34
|
+
stubfedora.expects(:connection).returns(mock("Connection", :find_objects =>fixture('find_multiple.xml')))
|
35
|
+
ActiveFedora::Base.fedora_connection = [stubfedora]
|
36
|
+
TestBase.expects(:active_fedora_find).with(FCREPO_ID).returns TestBase.new(:pid=>FCREPO_ID)
|
37
|
+
TestBase.expects(:active_fedora_find).with("demo:1").returns TestBase.new(:pid=>"demo:1")
|
38
|
+
TestBase.find_all_by_source("test").should be_a Array
|
39
|
+
end
|
40
|
+
it "should throw an error when no results and a bang" do
|
41
|
+
stubfedora = mock("Fedora")
|
42
|
+
stubfedora.expects(:connection).returns(mock("Connection", :find_objects =>fixture('find_none.xml')))
|
43
|
+
ActiveFedora::Base.fedora_connection = [stubfedora]
|
44
|
+
#ActiveRecord::Base
|
45
|
+
begin
|
46
|
+
TestBase.find_by_identifier!("dummy:1")
|
47
|
+
fail "should not successfully return from bang method with no results"
|
48
|
+
rescue Exception => e
|
49
|
+
e.should be_a ActiveRecord::RecordNotFound
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
ENV["environment"] ||= 'test'
|
2
|
+
require "bundler/setup"
|
3
|
+
|
4
|
+
if ENV['COVERAGE'] and RUBY_VERSION =~ /^1.9/
|
5
|
+
require 'simplecov'
|
6
|
+
require 'simplecov-rcov'
|
7
|
+
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
|
9
|
+
SimpleCov.start
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'active_record'
|
13
|
+
#require 'active_record/errors'
|
14
|
+
require 'active-fedora'
|
15
|
+
require 'rspec'
|
16
|
+
|
17
|
+
require 'support/mock_fedora'
|
18
|
+
require 'active_fedora_finders'
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.mock_with :mocha
|
22
|
+
config.color_enabled = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def fixture(file)
|
26
|
+
File.open(File.join(File.dirname(__FILE__), 'fixtures', file), 'rb')
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# copied directly from active-fedora
|
2
|
+
def mock_client
|
3
|
+
return @mock_client if @mock_client
|
4
|
+
@mock_client = mock("client")
|
5
|
+
@getter = mock("getter")
|
6
|
+
@getter.stubs(:get).returns('')
|
7
|
+
@mock_client.stubs(:[]).with("describe?xml=true").returns('')
|
8
|
+
@mock_client
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_get(pid, datastreams=nil, record_exists=false)
|
12
|
+
pid.gsub!(/:/, '%3A')
|
13
|
+
if record_exists
|
14
|
+
mock_client.stubs(:[]).with("objects/#{pid}?format=xml").returns(stub('get getter', :get=>'foobar'))
|
15
|
+
else
|
16
|
+
mock_client.stubs(:[]).with("objects/#{pid}?format=xml").raises(RestClient::ResourceNotFound)
|
17
|
+
end
|
18
|
+
mock_client.stubs(:[]).with("objects/#{pid}/datastreams?format=xml").returns(@getter)
|
19
|
+
datastreams ||= ['someData', 'withText', 'withText2', 'RELS-EXT']
|
20
|
+
datastreams.each do |dsid|
|
21
|
+
mock_client.stubs(:[]).with("objects/#{pid}/datastreams/#{dsid}?format=xml").returns(@getter)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def stub_ingest(pid=nil)
|
26
|
+
n = pid ? pid.gsub(/:/, '%3A') : nil
|
27
|
+
mock_client.expects(:[]).with("objects/#{n || 'new'}").returns(stub("ingester", :post=>pid))
|
28
|
+
end
|
29
|
+
|
30
|
+
def stub_add_ds(pid, dsids)
|
31
|
+
pid.gsub!(/:/, '%3A')
|
32
|
+
dsids.each do |dsid|
|
33
|
+
client = mock_client.stubs(:[]).with do |params|
|
34
|
+
/objects\/#{pid}\/datastreams\/#{dsid}/.match(params)
|
35
|
+
end
|
36
|
+
client.returns(stub("ds_adder", :post=>pid, :get=>''))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def stub_get_content(pid, dsids)
|
41
|
+
pid.gsub!(/:/, '%3A')
|
42
|
+
dsids.each do |dsid|
|
43
|
+
mock_client.stubs(:[]).with { |params| /objects\/#{pid}\/datastreams\/#{dsid}\/content/.match(params)}.returns(stub("content_accessor", :post=>pid, :get=>''))
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,232 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_fedora_finders
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benjamin Armintor
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: active-fedora
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.2.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activerecord
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 3.2.0
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.2.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: activesupport
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.2.0
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 3.2.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rubydora
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.5.9
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.5.9
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: yard
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: RedCloth
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rake
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ! '>='
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: rspec
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ! '>='
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 2.9.0
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 2.9.0
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: mocha
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - '='
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 0.10.5
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - '='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.10.5
|
174
|
+
description: A mixin library for ActiveFedora. Generates dynamic finder methods operating
|
175
|
+
against the FCRepo object search terms (DCES elements and object properties).
|
176
|
+
email:
|
177
|
+
- armintor@gmail.com
|
178
|
+
executables: []
|
179
|
+
extensions: []
|
180
|
+
extra_rdoc_files:
|
181
|
+
- LICENSE.txt
|
182
|
+
- README.textile
|
183
|
+
files:
|
184
|
+
- Gemfile
|
185
|
+
- LICENSE.txt
|
186
|
+
- README.textile
|
187
|
+
- Rakefile
|
188
|
+
- active_fedora_finders.gemspec
|
189
|
+
- lib/active_fedora_finders.rb
|
190
|
+
- lib/active_fedora_finders/version.rb
|
191
|
+
- lib/tasks/af_finders_dev.rake
|
192
|
+
- spec/config_helper.rb
|
193
|
+
- spec/finders_spec.rb
|
194
|
+
- spec/fixtures/find_multiple.xml
|
195
|
+
- spec/fixtures/find_none.xml
|
196
|
+
- spec/fixtures/find_one.xml
|
197
|
+
- spec/spec_helper.rb
|
198
|
+
- spec/support/mock_fedora.rb
|
199
|
+
homepage: https://github.com/barmintor/active_fedora_finders
|
200
|
+
licenses: []
|
201
|
+
post_install_message:
|
202
|
+
rdoc_options: []
|
203
|
+
require_paths:
|
204
|
+
- lib
|
205
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
206
|
+
none: false
|
207
|
+
requirements:
|
208
|
+
- - ! '>='
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
version: '0'
|
211
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
212
|
+
none: false
|
213
|
+
requirements:
|
214
|
+
- - ! '>='
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
requirements: []
|
218
|
+
rubyforge_project:
|
219
|
+
rubygems_version: 1.8.24
|
220
|
+
signing_key:
|
221
|
+
specification_version: 3
|
222
|
+
summary: A library for adding ActiveRecord-style dynamic finders to ActiveFedora::Base
|
223
|
+
subclasses.
|
224
|
+
test_files:
|
225
|
+
- spec/config_helper.rb
|
226
|
+
- spec/finders_spec.rb
|
227
|
+
- spec/fixtures/find_multiple.xml
|
228
|
+
- spec/fixtures/find_none.xml
|
229
|
+
- spec/fixtures/find_one.xml
|
230
|
+
- spec/spec_helper.rb
|
231
|
+
- spec/support/mock_fedora.rb
|
232
|
+
has_rdoc:
|