Skip to content

Commit 795ade2

Browse files
committed
Let identifier_field be customizable, analgous to timestamp_field
To be used for a feature I actually need in the ActiveRecordWrapper, and will implement there next. Sorry, haven't figured out how to test this at present. The customizable timestamp_field does not seem to be tested either.
1 parent f75cd31 commit 795ade2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/oai/provider.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@
155155
#
156156
# Valid options include:
157157
#
158-
# * `timestamp_field` - Specifies the model field to use as the update
158+
# * `timestamp_field` - Specifies the model field/method to use as the update
159159
# filter. Defaults to `updated_at`.
160+
# * `identifier_field` -- specifies the model field/method to use to get value to use
161+
# as oai identifier (method return value should not include prefix)
160162
# * `limit` - Maximum number of records to return in each page/set.
161163
# Defaults to 100, set to `nil` for all records in one page. Otherwise
162164
# the wrapper will paginate the result via resumption tokens.

lib/oai/provider/model.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ module OAI::Provider
2929
# see the ResumptionToken class for more details.
3030
#
3131
class Model
32-
attr_reader :timestamp_field
32+
attr_reader :timestamp_field, :identifier_field
3333

34-
def initialize(limit = nil, timestamp_field = 'updated_at')
34+
def initialize(limit = nil, timestamp_field = 'updated_at', identifier_field = 'id')
3535
@limit = limit
36+
@identifier_field = identifier_field
3637
@timestamp_field = timestamp_field
3738
end
3839

lib/oai/provider/response/record_response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def about_for(record)
5050

5151
# Namespace syntax suggested in http://www.openarchives.org/OAI/2.0/guidelines-oai-identifier.htm
5252
def identifier_for(record)
53-
"#{provider.prefix}:#{record.id}"
53+
"#{provider.prefix}:#{record.send( provider.model.identifier_field )}"
5454
end
5555

5656
def timestamp_for(record)

0 commit comments

Comments
 (0)