Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting ancestry identifier configurability #209

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) { w.object_id }
end.to change { config.ancestory_identifier_function.object_id }
end
end

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

Expand Down