Skip to content

Commit b9454a8

Browse files
committed
refactor(enmeshed): move serialization for creating IdentityAttributes 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
1 parent 11de0a1 commit b9454a8

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

lib/enmeshed/attribute.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,14 @@ def self.parse(content)
3232
desired_klass.new(**attributes.compact)
3333
end
3434

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

39-
def to_json(*)
40-
{
41-
content: {
42-
value: {
43-
'@type': @type,
44-
value: @value,
45-
},
46-
},
47-
}.to_json(*)
48-
end
49-
5043
def id
5144
@id ||= persistent_id
5245
end

lib/enmeshed/attribute/identity.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
module Enmeshed
44
class Attribute::Identity < Attribute
5+
# Serialize the Identity object to fit the content requirements when creating
6+
# an IdentityAttribute via the Connector API (available under Connector::CONNECTOR_URL)
7+
#
8+
# @return [String] JSON
9+
def to_json(*)
10+
{
11+
content: {
12+
value: {
13+
'@type': @type,
14+
value: @value,
15+
},
16+
},
17+
}.to_json(*)
18+
end
19+
520
private
621

722
def additional_attributes

0 commit comments

Comments
 (0)