Skip to content

Commit

Permalink
Add fullName attribute serialization logic
Browse files Browse the repository at this point in the history
Added the fullName attribute to language_spec.rb and language.rb to handle serialization and deserialization, ensuring that the full attribute details are included in the outputs and test cases. Also updated the descriptor to handle the presence of include_class correctly.
  • Loading branch information
afuno committed Sep 22, 2024
1 parent 01b7ee9 commit 9a375e6
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 23 deletions.
16 changes: 16 additions & 0 deletions examples/usual/example3/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Language < Datory::Base
uuid! :id

string! :name
string? :fullName, to: :full_name

# TODO: Need to prepare this example:
# {
Expand All @@ -32,6 +33,21 @@ class Language < Datory::Base
one? :lastEOLVersion, to: :last_eol, include: Version

many? :previousVersions, to: :previous, include: Version

# deserialize
getter :fullName do |**|
nil
end

# serialize
setter :full_name do |attributes:|
language_name = attributes.fetch(:name)
current_version_name = attributes.dig(:current, :name)

next language_name if current_version_name.blank?

"#{language_name} (#{current_version_name})"
end
end
end
end
5 changes: 4 additions & 1 deletion lib/datory/attributes/descriptor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def describe(service_class_name:, collection_of_attributes:) # rubocop:disable M
row << attribute.from.type
row << attribute.to.name
row << attribute.to.type
row << (include_class if include_class <= Datory::Base) if collection_of_attributes.include_class_exist?

if collection_of_attributes.include_class_exist? && !include_class.nil?
row << (include_class if include_class.respond_to?(:<=) && include_class <= Datory::Base)
end

rows << row
end
Expand Down
69 changes: 47 additions & 22 deletions spec/examples/usual/example3/language_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
{
id: "73031620-be3b-4088-9a78-5589ff7e1f61",
name: "Ruby",
fullName: "Ruby (3.3.1)",
currentVersion: {
name: "3.3.1",
releasedAt: nil,
Expand All @@ -161,6 +162,7 @@
{
id: "73031620-be3b-4088-9a78-5589ff7e1f61",
name: "Ruby",
fullName: "Ruby (3.3.1)",
currentVersion: {
name: "3.3.1",
releasedAt: nil,
Expand Down Expand Up @@ -374,17 +376,18 @@
expect { perform }.to(
output(
<<~TABLE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Usual::Example3::Language |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Attribute | From | To | As | Include |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| id | String | id | String | |
| name | String | name | String | |
| currentVersion | [Usual::Example3::Version, Hash] | current | [Usual::Example3::Version, Hash] | Usual::Example3::Version |
| lastEOLVersion | [Usual::Example3::Version, Hash, NilClass] | last_eol | [Usual::Example3::Version, Hash, NilClass] | Usual::Example3::Version |
| previousVersions | Array | previous | Array | Usual::Example3::Version |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Usual::Example3::Language |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Attribute | From | To | As | Include |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| id | String | id | String | |
| name | String | name | String | |
| fullName | [String, NilClass] | full_name | [String, NilClass] | |
| currentVersion | [Usual::Example3::Version, Hash] | current | [Usual::Example3::Version, Hash] | Usual::Example3::Version |
| lastEOLVersion | [Usual::Example3::Version, Hash, NilClass] | last_eol | [Usual::Example3::Version, Hash, NilClass] | Usual::Example3::Version |
| previousVersions | Array | previous | Array | Usual::Example3::Version |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TABLE
).to_stdout
)
Expand All @@ -400,17 +403,18 @@
expect { perform }.to(
output(
<<~TABLE
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Usual::Example3::Language |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Attribute | From | To | As | Include |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| id | String | id | String | |
| name | String | name | String | |
| currentVersion | [Usual::Example3::Version, Hash] | current | [Usual::Example3::Version, Hash] | Usual::Example3::Version |
| lastEOLVersion | [Usual::Example3::Version, Hash, NilClass] | last_eol | [Usual::Example3::Version, Hash, NilClass] | Usual::Example3::Version |
| previousVersions | Array | previous | Array | Usual::Example3::Version |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Usual::Example3::Language |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Attribute | From | To | As | Include |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| id | String | id | String | |
| name | String | name | String | |
| fullName | [String, NilClass] | full_name | [String, NilClass] | |
| currentVersion | [Usual::Example3::Version, Hash] | current | [Usual::Example3::Version, Hash] | Usual::Example3::Version |
| lastEOLVersion | [Usual::Example3::Version, Hash, NilClass] | last_eol | [Usual::Example3::Version, Hash, NilClass] | Usual::Example3::Version |
| previousVersions | Array | previous | Array | Usual::Example3::Version |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TABLE
).to_stdout
)
Expand Down Expand Up @@ -469,6 +473,27 @@
include: nil
}
},
fullName: {
from: {
name: :fullName,
type: [String, NilClass],
min: nil,
max: nil,
consists_of: false,
format: nil
},
to: {
name: :full_name,
type: [String, NilClass],
required: false,
default: nil,
min: nil,
max: nil,
consists_of: false,
format: nil,
include: nil
}
},
currentVersion: {
from: {
name: :currentVersion,
Expand Down

0 comments on commit 9a375e6

Please sign in to comment.