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

Improve Decodable implementation #7

Merged
merged 2 commits into from
Aug 30, 2024
Merged

Conversation

albertodebortoli
Copy link
Member

This PR improves the decoding logic of the models (using Decodable as God intended) addressing the feedback raised by @akuzminskyi in #5 (see my original reply).

func makeContext() -> [String: Any] {
[
"name": name,
"productType": productType.rawValue,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although the keys in the rest of the file use snake casing, I left this one to match the name of the property to avoid breaking backward compatibility with the Stencil file provided as part of the current major version.

"package_name": name,
"platforms": platforms,
"local_dependencies": localDependencies,
"remote_dependencies": remoteDependencies.map{ $0.makeContext() },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor:

Suggested change
"remote_dependencies": remoteDependencies.map{ $0.makeContext() },
"remote_dependencies": remoteDependencies.map { $0.makeContext() },

tot follow a style that you have

self.version = try container.decodeIfPresent(String.self, forKey: .version)
self.revision = try container.decodeIfPresent(String.self, forKey: .revision)
self.branch = try container.decodeIfPresent(String.self, forKey: .branch)
self.ref = (try? Ref(from: decoder)) ?? nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need ?? nil if try? already returns nil(nil ?? nil)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed why 🤣

@albertodebortoli albertodebortoli merged commit 351fae7 into main Aug 30, 2024
2 checks passed
@albertodebortoli albertodebortoli deleted the decoding-improvements branch August 30, 2024 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants