oai 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- RUBY_OAI_VERSION = '0.0.9'
1
+ RUBY_OAI_VERSION = '0.0.10'
2
2
 
3
3
  require 'rubygems'
4
4
  require 'rake'
@@ -54,11 +54,13 @@ module OAI::Provider::Metadata
54
54
  # 2. Try calling the pluralized name method on the model.
55
55
  # 3. Try calling the singular name method on the model
56
56
  def value_for(field, record, map)
57
- method = map[field] ? map[field].to_s : field.to_s
58
-
57
+ method = map[field] ? map[field].to_s : field.to_s
58
+
59
59
  if record.respond_to?(pluralize(method))
60
60
  record.send pluralize(method)
61
61
  elsif record.respond_to?(method)
62
+ # at this point, this function will throw a dep. error because of the call to type -- a reserved work
63
+ # in ruby
62
64
  record.send method
63
65
  else
64
66
  []
@@ -1,5 +1,4 @@
1
1
  require 'active_record'
2
-
3
2
  module OAI::Provider
4
3
  # = OAI::Provider::ActiveRecordWrapper
5
4
  #
@@ -35,7 +34,6 @@ module OAI::Provider
35
34
  model.find(:first,
36
35
  :order => "#{timestamp_field} desc").send(timestamp_field)
37
36
  end
38
-
39
37
  # A model class is expected to provide a method Model.sets that
40
38
  # returns all the sets the model supports. See the
41
39
  # activerecord_provider tests for an example.
@@ -46,7 +44,6 @@ module OAI::Provider
46
44
  def find(selector, options={})
47
45
  return next_set(options[:resumption_token]) if options[:resumption_token]
48
46
  conditions = sql_conditions(options)
49
-
50
47
  if :all == selector
51
48
  total = model.count(:id, :conditions => conditions)
52
49
  if @limit && total > @limit
@@ -93,9 +90,7 @@ module OAI::Provider
93
90
  :conditions => token_conditions(token),
94
91
  :limit => @limit,
95
92
  :order => "#{model.primary_key} asc")
96
-
97
93
  raise OAI::ResumptionTokenException.new unless records
98
-
99
94
  offset = records.last.send(model.primary_key.to_sym)
100
95
 
101
96
  PartialResult.new(records, token.next(offset))
@@ -124,9 +119,8 @@ module OAI::Provider
124
119
  sql = []
125
120
  sql << "#{timestamp_field} >= ?" << "#{timestamp_field} <= ?"
126
121
  sql << "set = ?" if opts[:set]
127
-
128
122
  esc_values = [sql.join(" AND ")]
129
- esc_values << opts[:from].localtime << opts[:until].localtime
123
+ esc_values << Time.parse(opts[:from]).localtime << Time.parse(opts[:until]).localtime #-- OAI 2.0 hack - UTC fix from record_responce
130
124
  esc_values << opts[:set] if opts[:set]
131
125
 
132
126
  return esc_values
@@ -134,3 +128,4 @@ module OAI::Provider
134
128
 
135
129
  end
136
130
  end
131
+
@@ -1,5 +1,4 @@
1
1
  require 'builder' unless defined?(Builder)
2
-
3
2
  module OAI
4
3
  module Provider
5
4
  module Response
@@ -9,7 +8,6 @@ module OAI
9
8
 
10
9
  class << self
11
10
  attr_reader :valid_options, :default_options, :required_options
12
-
13
11
  def valid_parameters(*args)
14
12
  @valid_options ||= []
15
13
  @valid_options = (@valid_options + args.dup).uniq
@@ -27,23 +25,23 @@ module OAI
27
25
  end
28
26
 
29
27
  end
30
-
31
28
  def initialize(provider, options = {})
32
29
  @provider = provider
33
30
  @options = internalize(options)
34
31
  raise OAI::ArgumentException.new unless valid?
35
32
  end
36
-
37
33
  def response
38
34
  @builder = Builder::XmlMarkup.new
39
35
  @builder.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
40
36
  @builder.tag!('OAI-PMH', header) do
41
37
  @builder.responseDate Time.now.utc.xmlschema
42
- @builder.request(provider.url, options)
38
+ #options parameter has been removed here because with it
39
+ #the data won't validate against oai validators. Without, it
40
+ #validates.
41
+ @builder.request(provider.url) #-- OAI 2.0 Hack - removed request options
43
42
  yield @builder
44
43
  end
45
44
  end
46
-
47
45
  private
48
46
 
49
47
  def header
@@ -54,7 +52,6 @@ module OAI
54
52
  http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd}
55
53
  }
56
54
  end
57
-
58
55
  def extract_identifier(id)
59
56
  id.sub("#{provider.prefix}/", '')
60
57
  end
@@ -67,9 +64,7 @@ module OAI
67
64
  if self.class.required_options
68
65
  return false unless (self.class.required_options - @options.keys).empty?
69
66
  end
70
-
71
67
  return false unless (@options.keys - self.class.valid_options).empty?
72
-
73
68
  populate_defaults
74
69
  end
75
70
 
@@ -95,7 +90,7 @@ module OAI
95
90
  return value if value.respond_to?(:strftime)
96
91
 
97
92
  Date.parse(value) # This will raise an exception for badly formatted dates
98
- Time.parse(value).utc # Sadly, this will not
93
+ Time.parse(value).utc # -- UTC Bug fix hack 8/08 not in core
99
94
  rescue
100
95
  raise OAI::ArgumentError.new
101
96
  end
@@ -119,3 +114,4 @@ module OAI
119
114
  end
120
115
  end
121
116
  end
117
+
@@ -13,7 +13,7 @@ module OAI::Provider::Response
13
13
  else
14
14
  r.adminEmail provider.email.to_s
15
15
  end
16
- r.earliestDatestamp provider.model.earliest
16
+ r.earliestDatestamp Time.parse(provider.model.earliest.to_s).utc.xmlschema
17
17
  r.deletedRecord provider.delete_support.to_s
18
18
  r.granularity provider.granularity
19
19
  end
@@ -23,4 +23,3 @@ module OAI::Provider::Response
23
23
  end
24
24
 
25
25
  end
26
-
@@ -1,5 +1,4 @@
1
1
  module OAI::Provider::Response
2
-
3
2
  class ListMetadataFormats < RecordResponse
4
3
  valid_parameters :identifier
5
4
 
@@ -17,7 +16,6 @@ module OAI::Provider::Response
17
16
  # Remove any format that this particular record can't be provided in.
18
17
  formats.reject! { |f| !record_supports(record, f.prefix) }
19
18
  end
20
-
21
19
  response do |r|
22
20
  r.ListMetadataFormats do
23
21
  formats.each do |format|
@@ -38,5 +36,4 @@ module OAI::Provider::Response
38
36
  end
39
37
 
40
38
  end
41
-
42
- end
39
+ end
@@ -1,11 +1,10 @@
1
1
  module OAI::Provider::Response
2
2
  class RecordResponse < Base
3
-
4
3
  def self.inherited(klass)
5
4
  klass.valid_parameters :metadata_prefix, :from, :until, :set
6
5
  klass.default_parameters :metadata_prefix => "oai_dc",
7
- :from => Proc.new {|x| Time.parse(x.provider.model.earliest.to_s) },
8
- :until => Proc.new {|x| Time.parse(x.provider.model.latest.to_s) }
6
+ :from => Proc.new {|x| Time.parse(x.provider.model.earliest.to_s) }, #-- OAI 2.0 hack - UTC
7
+ :until => Proc.new {|x| Time.parse(x.provider.model.latest.to_s) } #-- OAI 2.0 hack - UTC
9
8
  end
10
9
 
11
10
  # emit record header
@@ -20,7 +19,6 @@ module OAI::Provider::Response
20
19
  end
21
20
  end
22
21
  end
23
-
24
22
  # metadata - core routine for delivering metadata records
25
23
  #
26
24
  def data_for(record)
@@ -51,7 +49,6 @@ module OAI::Provider::Response
51
49
  elsif options[:resumption_token]
52
50
  OAI::Provider::ResumptionToken.extract_format(options[:resumption_token])
53
51
  end
54
-
55
52
  raise OAI::FormatException.new unless provider.format_supported?(format)
56
53
 
57
54
  format
@@ -65,4 +62,4 @@ module OAI::Provider::Response
65
62
  end
66
63
 
67
64
  end
68
- end
65
+ end
@@ -89,7 +89,7 @@ module OAI::Provider
89
89
  def encode_conditions
90
90
  encoded_token = @prefix.to_s.dup
91
91
  encoded_token << ".s(#{set})" if set
92
- encoded_token << ".f(#{from.utc.xmlschema})" if from
92
+ encoded_token << ".f(#{self.from.utc.xmlschema})" if self.from
93
93
  encoded_token << ".u(#{self.until.utc.xmlschema})" if self.until
94
94
  encoded_token << ":#{last}"
95
95
  end
@@ -33,7 +33,7 @@ class LibXMLTest < Test::Unit::TestCase
33
33
  records.each do |record|
34
34
  assert record.header.identifier
35
35
  next if record.deleted?
36
- assert_kind_of XML::Node, record.metadata
36
+ assert_kind_of LibXML::XML::Node, record.metadata
37
37
  end
38
38
  end
39
39
  end
@@ -18,9 +18,9 @@ class XpathTest < Test::Unit::TestCase
18
18
  return
19
19
  end
20
20
 
21
- doc = XML::Document.file('test/test.xml')
21
+ doc = LibXML::XML::Document.file('test/test.xml')
22
22
  assert_equal xpath(doc, './/responseDate'), '2006-09-11T14:33:15Z'
23
23
  assert_equal xpath(doc, './/foobar'), nil
24
24
  end
25
25
 
26
- end
26
+ end
@@ -7,9 +7,9 @@ class Record
7
7
  tags = 'tag',
8
8
  sets = nil,
9
9
  deleted = false,
10
- updated_at = Time.new.utc)
10
+ updated_at = Time.now.utc.xmlschema)
11
11
 
12
- @id = id;
12
+ @id = id
13
13
  @titles = titles
14
14
  @creator = creator
15
15
  @tags = tags
@@ -31,7 +31,6 @@ class Record
31
31
  end
32
32
  false
33
33
  end
34
-
35
34
  end
36
35
 
37
36
  class TestModel < OAI::Provider::Model
@@ -41,15 +40,15 @@ class TestModel < OAI::Provider::Model
41
40
  super(limit)
42
41
  @records = []
43
42
  @sets = []
44
- @earliest = Time.now
43
+ @earliest = Time.now.utc.xmlschema
45
44
  end
46
45
 
47
46
  def earliest
48
- (@records.min {|a,b| a.updated_at <=> b.updated_at }).updated_at
47
+ (@records.min {|a,b| a.updated_at <=> b.updated_at }).updated_at.utc.xmlschema
49
48
  end
50
49
 
51
50
  def latest
52
- @records.max {|a,b| a.updated_at <=> b.updated_at }.updated_at
51
+ @records.max {|a,b| a.updated_at <=> b.updated_at }.updated_at.utc.xmlschema
53
52
  end
54
53
 
55
54
  def sets
@@ -76,9 +75,14 @@ class TestModel < OAI::Provider::Model
76
75
  end
77
76
  else
78
77
  records = @records.select do |rec|
79
- ((opts[:set].nil? || rec.in_set(opts[:set])) &&
80
- (opts[:from].nil? || rec.updated_at >= opts[:from]) &&
81
- (opts[:until].nil? || rec.updated_at <= opts[:until]))
78
+ ((opts[:set].nil? || rec.in_set(opts[:set])) &&
79
+ (opts[:from].nil? || rec.updated_at >= opts[:from]) &&
80
+ (opts[:until].nil? || rec.updated_at <= opts[:until]))
81
+ #else
82
+ # ((opts[:set].nil? || rec.in_set(opts[:set])) &&
83
+ # (opts[:from].nil? || rec.updated_at >= opts[:from]) &&
84
+ # (opts[:until].nil? || rec.updated_at <= opts[:until]))
85
+ #end
82
86
  end
83
87
 
84
88
  if @limit && records.size > @limit
@@ -107,8 +111,8 @@ class TestModel < OAI::Provider::Model
107
111
  groups
108
112
  end
109
113
 
110
- def generate_records(number, timestamp = Time.now, sets = [], deleted = false)
111
- @earliest = timestamp.dup if @earliest.nil? || timestamp < @earliest
114
+ def generate_records(number, timestamp = Time.now.utc.xmlschema, sets = [], deleted = false)
115
+ @earliest = timestamp.dup if @earliest.nil? || timestamp.to_s < @earliest
112
116
 
113
117
  # Add any sets we don't already have
114
118
  sets = [sets] unless sets.respond_to?(:each)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: oai
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.9
7
- date: 2008-08-12 00:00:00 -07:00
6
+ version: 0.0.10
7
+ date: 2008-09-12 00:00:00 -07:00
8
8
  summary: A ruby library for working with the Open Archive Initiative Protocol for Metadata Harvesting (OAI-PMH)
9
9
  require_paths:
10
10
  - lib