Skip to content

Commit

Permalink
Extracting ancestry identifier configurability
Browse files Browse the repository at this point in the history
Prior to this commit, we assumed that a work's `id` was the mechanism
for always identifying a work in regards to it's ancestry/lineage.

However, for implmentations that incorproate slug behavior, that reality
is not always the case.

With this commit, we expose a configurable mechanism for altering the
ancestry functionality.

Related to:

- notch8/adventist-dl#354
- https://github.com/scientist-softserv/adventist-dl/issues/319
  • Loading branch information
jeremyf committed Apr 5, 2023
1 parent 8706082 commit f359d54
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/iiif_print/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def handle_after_create_fileset(file_set, user)
end
end

attr_writer :ancestory_identifier_function
# The function, with arity 1, that receives a work and returns it's identifier for the purposes
# of object ancestry.
# @return [Proc]
def ancestory_identifier_function
@ancestory_identifier_function ||= ->(work) { work.id }
end

attr_writer :excluded_model_name_solr_field_values
# By default, this uses an array of human readable types
# ex: ['Generic Work', 'Image']
Expand Down
13 changes: 12 additions & 1 deletion lib/iiif_print/lineage_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@ module LineageService
def self.ancestor_ids_for(object)
ancestor_ids ||= []
object.in_works.each do |work|
ancestor_ids << work.id
ancestor_ids << ancestry_identifier_for(work)
ancestor_ids += ancestor_ids_for(work) if work.is_child
end
ancestor_ids.flatten.compact.uniq
end

##
# @api public
#
# Given the :work return it's identifier
#
# @param [Object]
# @return [String]
def self.ancestry_identifier_for(work)
IiifPrint.config.ancestory_identifier_function.call(work)
end

##
# @param object [#ordered_works, #file_sets, #member_ids]
# @return [Array<String>] the ids of associated file sets
Expand Down
13 changes: 13 additions & 0 deletions spec/iiif_print/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
RSpec.describe IiifPrint::Configuration do
let(:config) { described_class.new }

describe '#ancestory_identifier_function' do
subject(:function) { config.ancestory_identifier_function }
it "is expected to be a lambda with an arity of one" do
expect(function.arity).to eq(1)
end

it "is configurable" do
expect do
config.ancestory_identifier_function = ->(w) { }
end.to change { config.ancestory_identifier_function.object_id }
end
end

describe "#metadata_fields" do
subject { config.metadata_fields }

Expand Down

0 comments on commit f359d54

Please sign in to comment.