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

fix: serialization of properties using lambda as a property attribute #202

Closed
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
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ GEM
macaddr (~> 1.0)

PLATFORMS
x86_64-darwin-23
aarch64-linux
x86_64-linux

Expand Down
9 changes: 7 additions & 2 deletions lib/ontologies_linked_data/serializers/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
def self.get_submission_languages(submission_natural_language = [])
submission_natural_language = submission_natural_language.values.flatten if submission_natural_language.is_a?(Hash)
submission_natural_language.map { |natural_language| natural_language.to_s['iso639'] && natural_language.to_s.split('/').last[0..1].to_sym }.compact
end
end

def self.type(current_cls, hashed_obj)
if current_cls.respond_to?(:type_uri)
Expand Down Expand Up @@ -101,7 +101,12 @@
predicate = { "@id" => linked_model.type_uri.to_s, "@type" => "@id" }
else
# use the original predicate property if set
predicate_attr = current_cls.model_settings[:attributes][attr][:property] || attr
predicate_attr = if current_cls.model_settings[:attributes][attr][:property].is_a?(Proc)
attr

Check warning on line 105 in lib/ontologies_linked_data/serializers/json.rb

View check run for this annotation

Codecov / codecov/patch

lib/ontologies_linked_data/serializers/json.rb#L105

Added line #L105 was not covered by tests
else
current_cls.model_settings[:attributes][attr][:property] || attr
end

# predicate with custom namespace
# if the namespace can be resolved by the namespaces added in Goo then it will be resolved.
predicate = "#{Goo.vocabulary(current_cls.model_settings[:attributes][attr][:namespace])&.to_s}#{predicate_attr}"
Expand Down