-
Notifications
You must be signed in to change notification settings - Fork 21
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
♻️ Extract Bulkrax::FactoryClassFinder #900
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
module Bulkrax | ||
class FactoryClassFinder | ||
## | ||
# @param entry [Bulkrax::Entry] | ||
# @return [Class] | ||
def self.find(entry:) | ||
new(entry: entry).find | ||
end | ||
|
||
def initialize(entry:) | ||
@entry = entry | ||
end | ||
attr_reader :entry | ||
|
||
## | ||
# @return [Class] when we are able to derive the class based on the {#name}. | ||
# @return [Nil] when we encounter errors with constantizing the {#name}. | ||
# @see #name | ||
def find | ||
# TODO: We have a string, now we want to consider how we coerce. Let's say we have Work and | ||
# WorkResource in our upstream application. Work extends ActiveFedora::Base and is legacy. | ||
# And WorkResource extends Valkyrie::Resource and is where we want to be moving. We may want | ||
# to coerce the "Work" name into "WorkResource" | ||
name.constantize | ||
rescue NameError | ||
nil | ||
rescue | ||
entry.default_work_type.constantize | ||
end | ||
|
||
## | ||
# @api private | ||
# @return [String] | ||
def name | ||
fc = if entry.parsed_metadata&.[]('model').present? | ||
Array.wrap(entry.parsed_metadata['model']).first | ||
elsif entry.importerexporter&.mapping&.[]('work_type').present? | ||
# Because of delegation's nil guard, we're reaching rather far into the implementation | ||
# details. | ||
Array.wrap(entry.parsed_metadata['work_type']).first | ||
else | ||
# The string might be frozen, so lets duplicate | ||
entry.default_work_type.dup | ||
end | ||
|
||
# Let's coerce this into the right shape. | ||
fc.tr!(' ', '_') | ||
fc.downcase! if fc.match?(/[-_]/) | ||
fc.camelcase | ||
rescue | ||
entry.default_work_type | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
module Bulkrax | ||
RSpec.describe RdfFileSetEntry, type: :model do | ||
describe '#default_work_type' do | ||
subject { described_class.new.default_work_type } | ||
it { is_expected.to eq("::FileSet") } | ||
end | ||
|
||
describe '#factory_class' do | ||
subject { described_class.new.factory_class } | ||
it { is_expected.to eq(::FileSet) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeremyf this dry-monads is now a dev dependency of bulkrax with this change. but I dont see where you are actually using it? can this come out or do we need to add it to the gemspec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the
require 'dry/monads'
the specs failed to load. This was the quickest adjustment.Looking at it now, my assumption is that
dry/monads
is a development dependency in that we are creating transactions and merging those transactions.So the shorter solution would be to move this to a development dependency.