Skip to content

Commit

Permalink
refactor(enmeshed): Move serialization for creating IdentityAttribute…
Browse files Browse the repository at this point in the history
…s to `Attribute::Identity`

The former implementation of `Attibute.to_json` was very specific to IdentityAttributes.
It actually only worked for simple IdentityAttributes and would need adaptations for complex
IdentityAttributes.

Part of XI-6523
  • Loading branch information
nenock committed Feb 5, 2025
1 parent 5dad0f5 commit 68ddf44
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
15 changes: 4 additions & 11 deletions lib/enmeshed/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,14 @@ def self.parse(content)
desired_klass.new(**attributes.compact)
end

# Serialize all available attributes of an Attribute object.
# E.g. for sharing it when making the API request to create a relationship template.
#
# @return [Hash]
def to_h
default_attributes.deep_merge(additional_attributes)
end

def to_json(*)
{
content: {
value: {
'@type': @type,
value: @value,
},
},
}.to_json(*)
end

def id
@id ||= persistent_id
end
Expand Down
16 changes: 16 additions & 0 deletions lib/enmeshed/attribute/identity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

module Enmeshed
class Attribute::Identity < Attribute

Check warning on line 5 in lib/enmeshed/attribute/identity.rb

View workflow job for this annotation

GitHub Actions / lint

[rubocop] reported by reviewdog 🐶 Extra empty line detected at class body beginning. Raw Output: lib/enmeshed/attribute/identity.rb:5:1: C: Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body beginning.
# Serialize the Identity object to fit the content requirements when creating
# an IdentityAttribute via the Connector API (available under Connector::CONNECTOR_URL)
#
# @return [String] JSON
def to_json(*)
{
content: {
value: {
'@type': @type,
value: @value,
},
},
}.to_json(*)
end

private

def additional_attributes
Expand Down

0 comments on commit 68ddf44

Please sign in to comment.