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

Feature: Get the correct type for skos concepts #162

Closed
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
20 changes: 19 additions & 1 deletion lib/ontologies_linked_data/serializers/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def self.serialize(obj, options = {})
prefixed_id = LinkedData.settings.replace_url_prefix ? hashed_obj.id.to_s.gsub(LinkedData.settings.id_url_prefix, LinkedData.settings.rest_url_prefix) : hashed_obj.id.to_s
hash["@id"] = prefixed_id
end

# Add the type
hash["@type"] = current_cls.type_uri.to_s if hash["@id"] && current_cls.respond_to?(:type_uri)
hash["@type"] = type(current_cls, hashed_obj) if hash["@id"]

# Generate links
# NOTE: If this logic changes, also change in xml.rb
Expand All @@ -41,6 +42,23 @@ def self.serialize(obj, options = {})

private

def self.type(current_cls, hashed_obj)
if current_cls.respond_to?(:type_uri)
# For internal class
proc = current_cls
elsif hashed_obj.respond_to?(:type_uri)
# For External and Interportal class
proc = hashed_obj
end

collection = hashed_obj.respond_to?(:collection) ? hashed_obj.collection : nil
if collection
proc.type_uri(collection).to_s
else
proc.type_uri.to_s
end
end

def self.generate_context(object, serialized_attrs = [], options = {})
return remove_unused_attrs(CONTEXTS[object.hash], serialized_attrs) unless CONTEXTS[object.hash].nil?
hash = {}
Expand Down