ruby-fedora 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
metadata CHANGED
@@ -1,46 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Matt Zumwalt
7
+ - MediaShelf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-19 00:00:00 -06:00
12
+ date: 2009-02-04 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: facets
16
+ name: xml-simple
17
17
  type: :runtime
18
18
  version_requirement:
19
19
  version_requirements: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 2.4.0
23
+ version: 1.0.11
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
- name: xml-simple
27
- type: :runtime
26
+ name: newgem
27
+ type: :development
28
28
  version_requirement:
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.11
33
+ version: 1.2.3
34
34
  version:
35
35
  - !ruby/object:Gem::Dependency
36
- name: mime-types
37
- type: :runtime
36
+ name: mocha
37
+ type: :development
38
38
  version_requirement:
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: "1.15"
43
+ version: 0.9.4
44
44
  version:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: hoe
@@ -50,11 +50,11 @@ dependencies:
50
50
  requirements:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: 1.8.2
53
+ version: 1.8.0
54
54
  version:
55
- description: Ruby API for Fedora
55
+ description: FIX (describe your package)
56
56
  email:
57
- - matt.zumwalt@yourmediashelf.com>
57
+ - matt.zumwalt@yourmediashelf.com
58
58
  executables: []
59
59
 
60
60
  extensions: []
@@ -65,6 +65,8 @@ extra_rdoc_files:
65
65
  - History.txt
66
66
  - License.txt
67
67
  - Manifest.txt
68
+ - PostInstall.txt
69
+ - README.rdoc
68
70
  - README.txt
69
71
  files:
70
72
  - COPYING.LESSER.txt
@@ -72,23 +74,9 @@ files:
72
74
  - History.txt
73
75
  - License.txt
74
76
  - Manifest.txt
77
+ - PostInstall.txt
78
+ - README.rdoc
75
79
  - README.txt
76
- - Rakefile
77
- - config/hoe.rb
78
- - config/requirements.rb
79
- - lib/active_fedora.rb
80
- - lib/active_fedora/base.rb
81
- - lib/active_fedora/content_model.rb
82
- - lib/active_fedora/datastream.rb
83
- - lib/active_fedora/fedora_object.rb
84
- - lib/active_fedora/metadata_datastream.rb
85
- - lib/active_fedora/model.rb
86
- - lib/active_fedora/property.rb
87
- - lib/active_fedora/qualified_dublin_core_datastream.rb
88
- - lib/active_fedora/relationship.rb
89
- - lib/active_fedora/rels_ext_datastream.rb
90
- - lib/active_fedora/semantic_node.rb
91
- - lib/active_fedora/solr_service.rb
92
80
  - lib/fedora/base.rb
93
81
  - lib/fedora/connection.rb
94
82
  - lib/fedora/datastream.rb
@@ -96,16 +84,16 @@ files:
96
84
  - lib/fedora/formats.rb
97
85
  - lib/fedora/generic_search.rb
98
86
  - lib/fedora/repository.rb
87
+ - lib/fedora/repository.rb.orig
99
88
  - lib/ruby-fedora.rb
100
89
  - lib/util/class_level_inheritable_attributes.rb
101
- - setup.rb
102
- - solr/config/schema.xml
90
+ - tasks/rspec.rake
103
91
  has_rdoc: true
104
- homepage: http://rubyfedora.rubyforge.org
105
- post_install_message:
92
+ homepage: FIX (url)
93
+ post_install_message: PostInstall.txt
106
94
  rdoc_options:
107
95
  - --main
108
- - README.txt
96
+ - README.rdoc
109
97
  require_paths:
110
98
  - lib
111
99
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -122,10 +110,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
110
  version:
123
111
  requirements: []
124
112
 
125
- rubyforge_project: rubyfedora
113
+ rubyforge_project: ruby-fedora
126
114
  rubygems_version: 1.3.1
127
115
  signing_key:
128
116
  specification_version: 2
129
- summary: Ruby API for Fedora
130
- test_files:
131
- - test/test_helper.rb
117
+ summary: FIX (describe your package)
118
+ test_files: []
119
+
data/Rakefile DELETED
@@ -1,9 +0,0 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
3
- require 'rake/clean'
4
-
5
- Dir['tasks/**/*.rake'].each { |rake| load rake }
6
- CLEAN.include('**/*.orig')
7
-
8
- task :default=>:spec
9
-
data/config/hoe.rb DELETED
@@ -1,68 +0,0 @@
1
- require 'ruby-fedora'
2
-
3
- AUTHOR = 'Matt Zumwalt' # can also be an array of Authors
4
- EMAIL = 'matt.zumwalt@yourmediashelf.com>'
5
- DESCRIPTION = "Ruby API for Fedora"
6
- GEM_NAME = 'ruby-fedora' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'rubyfedora' # The unix name for your project
8
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
-
11
- @config_file = "~/.rubyforge/user-config.yml"
12
- @config = nil
13
- RUBYFORGE_USERNAME = "unknown"
14
- def rubyforge_username
15
- unless @config
16
- begin
17
- @config = YAML.load(File.read(File.expand_path(@config_file)))
18
- rescue
19
- puts <<-EOS
20
- ERROR: No rubyforge config file found: #{@config_file}
21
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
- - See http://newgem.rubyforge.org/rubyforge.html for more details
23
- EOS
24
- exit
25
- end
26
- end
27
- RUBYFORGE_USERNAME.replace @config["username"]
28
- end
29
-
30
-
31
- REV = nil
32
- # UNCOMMENT IF REQUIRED:
33
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
- VERS = Fedora::VERSION::STRING + (REV ? ".#{REV}" : "")
35
- RDOC_OPTS = ['--quiet', '--title', 'RubyFedora documentation',
36
- "--opname", "index.html",
37
- "--line-numbers",
38
- "--main", "README",
39
- "--inline-source"]
40
-
41
- class Hoe
42
- def extra_deps
43
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
- @extra_deps
45
- end
46
- end
47
-
48
- # Generate all the Rake tasks
49
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
- p.developer(AUTHOR, EMAIL)
52
- p.description = DESCRIPTION
53
- p.summary = DESCRIPTION
54
- p.url = HOMEPATH
55
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
- p.test_globs = ["test/**/test_*.rb"]
57
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
-
59
- # == Optional
60
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
- p.extra_deps = [['facets', '>=2.4.0'], ['xml-simple', '>=1.0.11'], ['mime-types', '>=1.15']]
62
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
63
- end
64
-
65
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
66
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
67
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
68
- hoe.rsync_args = '-av --delete --ignore-errors'
@@ -1,24 +0,0 @@
1
- require 'fileutils'
2
- include FileUtils
3
-
4
- require 'rubygems'
5
- %w[rake hoe rubigen facets extlib xml-simple solr-ruby mime-types activeresource].each do |req_gem|
6
- case req_gem
7
- when "solr-ruby": req_file_name = "solr"
8
- when "mime-types": req_file_name = "mime/types"
9
- when "xml-simple": req_file_name = "xmlsimple"
10
- when "activeresource": req_file_name = "active_resource"
11
- else req_file_name = req_gem
12
- end
13
- begin
14
- require req_file_name
15
- rescue LoadError
16
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
17
- puts "Installation: gem install #{req_gem} -y"
18
- exit
19
- end
20
- end
21
-
22
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
23
-
24
- require 'ruby-fedora'
data/lib/active_fedora.rb DELETED
@@ -1,41 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) unless
2
- $LOAD_PATH.include?(File.dirname(__FILE__)) ||
3
- $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
4
-
5
- # Currently using ExtLib::Assertions. Could just pull that method into this code base...
6
- gem 'extlib', '>=0.9.5'
7
- require 'extlib'
8
-
9
- module ActiveFedora #:nodoc:
10
- module VERSION #:nodoc:
11
- unless defined? MAJOR
12
- MAJOR = 0
13
- MINOR = 9
14
- TINY = 0
15
-
16
- STRING = [MAJOR, MINOR, TINY].join('.')
17
- end
18
- end
19
-
20
- def self.repository
21
- #RubyFedora::Repository.instance == nil? FedoraRepository.register(Repository.default_name) | Repository.instance
22
- end
23
-
24
- end
25
-
26
-
27
- require 'active_fedora/base'
28
- require 'active_fedora/model'
29
- require 'active_fedora/property'
30
- require 'active_fedora/metadata_datastream'
31
- require 'active_fedora/qualified_dublin_core_datastream'
32
- require 'active_fedora/fedora_object'
33
- require 'active_fedora/semantic_node'
34
- require 'active_fedora/rels_ext_datastream'
35
- require 'active_fedora/solr_service'
36
- require 'active_fedora/content_model'
37
-
38
-
39
-
40
-
41
-
@@ -1,292 +0,0 @@
1
- require 'ruby-fedora'
2
- require "rexml/document"
3
-
4
- require 'util/class_level_inheritable_attributes'
5
- require 'active_fedora/datastream'
6
- require 'active_fedora/relationship'
7
- require 'active_fedora/model'
8
-
9
-
10
- module ActiveFedora
11
-
12
- class Base
13
- include MediaShelfClassLevelInheritableAttributes
14
- ms_inheritable_attributes :ds_specs
15
- include Model
16
- include SemanticNode
17
- def new_object?
18
- @new_object
19
- end
20
-
21
- def initialize(attrs = {})
22
- unless attrs[:pid]
23
- attrs = attrs.merge!({:pid=>Fedora::Repository.instance.nextid})
24
- @new_object=true
25
- else
26
- @new_object=false;
27
- end
28
- @inner_object = Fedora::FedoraObject.new(attrs)
29
- @datastreams = {}
30
- configure_defined_datastreams
31
- end
32
- def self.has_metadata(args, &block)
33
- @ds_specs ||= Hash.new
34
- @ds_specs[args[:name]]= [args[:type], block]
35
- end
36
-
37
- def save
38
- # If it's a new object, set the conformsTo relationship for Fedora CMA
39
- if new_object?
40
- add_relationship(:conforms_to, ActiveFedora::ContentModel.pid_from_ruby_class(self.class))
41
- end
42
- @new_object =false
43
- Fedora::Repository.instance.save(@inner_object)
44
- datastreams_in_memory.each do |k,ds|
45
- if ds.dirty? || ds.new_object?
46
- if ds.kind_of?(ActiveFedora::MetadataDatastream)
47
- metadata_is_dirty = true
48
- end
49
- ds.save
50
- end
51
- self.update_index if metadata_is_dirty == true
52
- end
53
- end
54
-
55
- def delete
56
- Fedora::Repository.instance.delete(@inner_object)
57
- escaped_pid = self.pid.gsub(/(:)/, '\\:')
58
- SolrService.instance.conn.delete(escaped_pid)
59
- end
60
-
61
- # Returns all known datastreams for the object. If the object has been saved to fedora, the persisted datastreams will be included.
62
- # Datastreams that have been modified in memory are given preference over the copy in Fedora.
63
- def datastreams
64
- if @new_object
65
- @datastreams = datastreams_in_memory
66
- else
67
- @datastreams = datastreams_in_fedora.merge(datastreams_in_memory)
68
- end
69
-
70
- end
71
-
72
- def datastreams_in_fedora
73
- mds = {}
74
- self.datastreams_xml['datastream'].each do |ds|
75
- ds.merge!({:pid => self.pid, :dsID => ds["dsid"]})
76
- if ds["dsid"] == "RELS-EXT"
77
- mds.merge!({ds["dsid"] => ActiveFedora::RelsExtDatastream.new(ds)})
78
- else
79
- mds.merge!({ds["dsid"] => ActiveFedora::Datastream.new(ds)})
80
- end
81
- mds[ds["dsid"]].new_object = false
82
- end
83
- mds
84
- end
85
-
86
- def datastreams_in_memory
87
- @datastreams ||= Hash.new
88
- end
89
-
90
- def datastreams_xml
91
- datastreams_xml = XmlSimple.xml_in(Fedora::Repository.instance.fetch_custom(self.pid, :datastreams))
92
- end
93
-
94
- def add_datastream(datastream)
95
- datastream.pid = self.pid
96
- datastreams[datastream.dsid] = datastream
97
- return true
98
- end
99
- # Adds datastream to the object. Saves the datastream to fedora upon adding.
100
- def add(datastream)
101
- warn "Warning: ActiveFedora::Base.add has been deprected. Use add_datastream"
102
- add_datastream(datastream)
103
- end
104
-
105
- def metadata_streams
106
- results = []
107
- datastreams.each_value do |ds|
108
- if ds.kind_of?(ActiveFedora::MetadataDatastream)
109
- results<<ds
110
- end
111
- end
112
- return results
113
- end
114
-
115
- def file_streams
116
- results = []
117
- datastreams.each_value do |ds|
118
- if !ds.kind_of?(ActiveFedora::MetadataDatastream)
119
- dsid = ds.dsid
120
- if dsid != "DC" && dsid != "RELS-EXT"
121
- results<<ds
122
- end
123
- end
124
- end
125
- return results
126
- end
127
-
128
- # DC Datastream
129
- def dc
130
- #dc = REXML::Document.new(datastreams["DC"].content)
131
- return datastreams["DC"]
132
- end
133
-
134
- # Returns the RELS-EXT Datastream
135
- # Tries to grab from in-memory datastreams first
136
- # Failing that, attempts to load from Fedora and addst to in-memory datastreams
137
- # Failing that, creates a new RelsExtDatastream and adds it to the object
138
- def rels_ext
139
- if !datastreams.has_key?("RELS-EXT")
140
- add_datastream(ActiveFedora::RelsExtDatastream.new)
141
- end
142
- return datastreams["RELS-EXT"]
143
- end
144
-
145
- # @returns Hash of relationships, as defined by SemanticNode
146
- # Rely on rels_ext datastream to track relationships array
147
- # Overrides accessor for relationships array used by SemanticNode.
148
- def relationships
149
- return rels_ext.relationships
150
- end
151
-
152
- # Add a Rels-Ext relationship to the Object.
153
- # @param predicate
154
- # @param object Either a string URI or an object that responds to .pid
155
- def add_relationship(predicate, obj)
156
- #predicate = ActiveFedora::RelsExtDatastream.predicate_lookup(predicate)
157
- r = ActiveFedora::Relationship.new(:subject=>:self, :predicate=>predicate, :object=>obj)
158
- rels_ext.add_relationship(r)
159
- rels_ext.dirty = true
160
- end
161
-
162
- def inner_object
163
- @inner_object
164
- end
165
-
166
- def pid
167
- @inner_object.pid
168
- end
169
-
170
- def to_param
171
- self.pid
172
- end
173
- def internal_uri
174
- "info:fedora/#{pid}"
175
- end
176
-
177
- def state
178
- @inner_object.state
179
- end
180
-
181
- def owner_id
182
- @inner_object.owner_id
183
- end
184
-
185
- def create_date
186
- @inner_object.create_date unless new_object?
187
- end
188
-
189
- def modified_date
190
- @inner_object.modified_date unless new_object?
191
- end
192
-
193
- def errors
194
- @inner_object.errors
195
- end
196
-
197
- def label
198
- @inner_object.label
199
- end
200
- def self.deserialize(doc)
201
- pid = doc.elements['/foxml:digitalObject'].attributes['PID']
202
- proto = self.new(:pid=>pid)
203
- proto.datastreams.each do |name,ds|
204
- doc.elements.each("//foxml:datastream[@ID='#{name}']") do |el|
205
- proto.datastreams[name]=ds.class.from_xml(ds, el)
206
- end
207
- end
208
- proto
209
- end
210
-
211
- def fields
212
- fields = {:id => {:values => [pid]}, :system_create_date => {:values => [self.create_date]}, :system_modified_date => {:values => [self.modified_date]}, :active_fedora_model_field => {:values => [self.class.inspect]}}
213
- datastreams.values.each do |ds|
214
- fields.merge!(ds.fields) if ds.kind_of?(ActiveFedora::MetadataDatastream)
215
- end
216
- return fields
217
- end
218
-
219
- def to_xml(xml=REXML::Document.new("<xml><fields/><content/></xml>"))
220
- fields_xml = xml.root.elements['fields']
221
- {:id => pid, :system_create_date => self.create_date, :system_modified_date => self.modified_date, :active_fedora_model_field => self.class.inspect}.each_pair do |attribute_name, value|
222
- el = REXML::Element.new(attribute_name.to_s)
223
- el.text = value
224
- fields_xml << el
225
- end
226
- datastreams.each_value do |ds|
227
- ds.to_xml(fields_xml) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::RelsExtDatastream)
228
- end
229
- return xml.to_s
230
- end
231
-
232
- def to_solr(solr_doc = Solr::Document.new)
233
- solr_doc << {:id => pid, :system_create_date => self.create_date, :system_modified_date => self.modified_date, :active_fedora_model_field => self.class.inspect}
234
- datastreams.each_value do |ds|
235
- solr_doc = ds.to_solr(solr_doc) if ds.kind_of?(ActiveFedora::MetadataDatastream) || ds.kind_of?(ActiveFedora::RelsExtDatastream)
236
- end
237
- return solr_doc
238
- end
239
-
240
- # Updates Solr index
241
- def update_index
242
- solr_doc = self.to_solr
243
- SolrService.instance.conn.update(solr_doc)
244
- end
245
-
246
- def update_attributes(params={})
247
- params.each do |k,v|
248
- datastreams.values.each do |d|
249
- if d.fields[k.to_sym]
250
- d.send("#{k}_values=", v)
251
- end
252
- end
253
- end
254
- end
255
-
256
- def update_indexed_attributes(params={})
257
- params.each do |key,value|
258
- datastreams.each do |dsn, dstream|
259
- if dstream.fields[key.to_sym]
260
- aname="#{key}_values"
261
- curval = dstream.send("#{aname}")
262
- cpv=value.dup#copy this, we'll need the original for the next ds
263
- cpv.delete_if do |y,z|
264
- if curval[y.to_i] and y.to_i > -1
265
- curval[y.to_i]=z
266
- true
267
- else
268
- false
269
- end
270
- end
271
- cpv.each { |y,z| curval<<z}#just append everything left
272
- dstream.send("#{aname}=", curval) #write it back to the ds
273
- end
274
- end
275
- end
276
-
277
- end
278
-
279
- private
280
- def configure_defined_datastreams
281
- if self.class.ds_specs
282
- self.class.ds_specs.each do |name,ar|
283
- ds = ar.first.new(:dsid=>name)
284
- ar.last.call(ds)
285
- self.add_datastream(ds)
286
- end
287
- end
288
- end
289
-
290
-
291
- end
292
- end