-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support transformation of values without needing format-specific custom methods #178
Comments
@HassanAkbar can you please elaborate this task? Is the "value proc" for value validation or for processing the input/output values? |
@ronaldtse From what I understand this was for processing the input/output of the values i.e class Person < Lutaml::Model::Serializable
attribute :id, :string, value: -> { |id| id.capitalize }
end
p = Person.new({ id: "abc-123" })
puts p.id
#=> "ABC-123" Now thinking about it I have a question, do we need to support different |
Ah, now I remember. The "value proc" is meant to handle the simple usage of custom methods, where we are simply going to transfer the import/export of values, without needing complex processing of custom methods, which requires the user to handle the different formats. Maybe it should just be called "value transform"? We should differentiate the input and output of values at the attribute level. Or should this go into the format-specific level? Transforming values at the attribute-levelclass Person < Lutaml::Model::Serializable
attribute :id, :string, transform: {
import: -> { |id| id.capitalize },
export: -> { |id| id }
}
end Transforming values at the format levelclass Person < Lutaml::Model::Serializable
attribute :id, :string
xml do
map_element 'Id', to: :id, transform: {
import: -> { |id| id.capitalize },
export: -> { |id| id }
}
end
end QuestionWhich one? |
@ronaldtse I think if we want the user not to handle multiple format, then adding it to the attribute level seems more reasonable. |
No description provided.
The text was updated successfully, but these errors were encountered: