-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
func makeContext() -> [String: Any] { | ||
[ | ||
"name": name, | ||
"productType": productType.rawValue, |
There was a problem hiding this comment.
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.
Sources/Core/Spec+Context.swift
Outdated
"package_name": name, | ||
"platforms": platforms, | ||
"local_dependencies": localDependencies, | ||
"remote_dependencies": remoteDependencies.map{ $0.makeContext() }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor:
"remote_dependencies": remoteDependencies.map{ $0.makeContext() }, | |
"remote_dependencies": remoteDependencies.map { $0.makeContext() }, |
tot follow a style that you have
Sources/Models/Spec.swift
Outdated
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed why 🤣
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).