-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not prefix default project artifacts (#4426)
Summary: - Convert project name to enum with the `Default` variant. - Update places where we're generating names for fragments/operations to use new formatter Pull Request resolved: #4426 Test Plan: cargo test in OSS sanscastle Reviewed By: voideanvalue Differential Revision: D48803554 Pulled By: alunyov fbshipit-source-id: c3e20da14325371dbb0265aab2204cd0ce770eab
- Loading branch information
1 parent
563c570
commit 27893cc
Showing
36 changed files
with
215 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use std::fmt; | ||
|
||
use intern::string_key::Intern; | ||
use intern::string_key::StringKey; | ||
use intern::Lookup; | ||
use serde::Deserialize; | ||
use serde::Deserializer; | ||
use serde::Serialize; | ||
use serde::Serializer; | ||
|
||
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] | ||
pub enum ProjectName { | ||
Default, | ||
Named(StringKey), | ||
} | ||
|
||
impl ProjectName { | ||
pub fn generate_name_for_object_and_field( | ||
&self, | ||
object_name: StringKey, | ||
field_name: StringKey, | ||
) -> String { | ||
match self { | ||
ProjectName::Named(project_name) => { | ||
format!("{}_{}__{}", project_name, object_name, field_name) | ||
} | ||
ProjectName::Default => format!("{}__{}", object_name, field_name), | ||
} | ||
} | ||
} | ||
|
||
impl Default for ProjectName { | ||
fn default() -> Self { | ||
Self::Default | ||
} | ||
} | ||
|
||
impl fmt::Display for ProjectName { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
if let Self::Named(value) = self { | ||
write!(f, "{}", value) | ||
} else { | ||
write!(f, "default") | ||
} | ||
} | ||
} | ||
|
||
impl From<StringKey> for ProjectName { | ||
fn from(key: StringKey) -> Self { | ||
match key.lookup() { | ||
"default" => Self::Default, | ||
_ => Self::Named(key), | ||
} | ||
} | ||
} | ||
|
||
impl From<ProjectName> for StringKey { | ||
fn from(project_name: ProjectName) -> Self { | ||
match project_name { | ||
ProjectName::Default => "default".intern(), | ||
ProjectName::Named(name) => name, | ||
} | ||
} | ||
} | ||
|
||
impl Serialize for ProjectName { | ||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: Serializer, | ||
{ | ||
serializer.serialize_str(match self { | ||
ProjectName::Default => "default", | ||
ProjectName::Named(name) => name.lookup(), | ||
}) | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for ProjectName { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
Deserialize::deserialize(deserializer).map(|s: String| match s.as_str() { | ||
"default" => ProjectName::Default, | ||
s => ProjectName::Named(s.intern()), | ||
}) | ||
} | ||
} |
Oops, something went wrong.