Skip to content

Commit

Permalink
Make metadata fields internals (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Apr 13, 2020
1 parent f7e4c69 commit 8593c9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cargo-insta/src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl PendingSnapshot {
pub fn summary(&self) -> String {
use std::fmt::Write;
let mut rv = String::new();
if let Some(ref source) = self.new.metadata().source {
if let Some(source) = self.new.metadata().source() {
write!(&mut rv, "{}", source).unwrap();
}
if let Some(line) = self.line {
Expand Down
15 changes: 13 additions & 2 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,24 @@ impl PendingInlineSnapshot {
pub struct MetaData {
/// The source file (relative to workspace root).
#[serde(skip_serializing_if = "Option::is_none")]
pub source: Option<String>,
pub(crate) source: Option<String>,
/// Optionally the expression that created the snapshot.
#[serde(skip_serializing_if = "Option::is_none")]
pub expression: Option<String>,
pub(crate) expression: Option<String>,
}

impl MetaData {
/// Returns the absolute source path.
pub fn source(&self) -> Option<&str> {
self.source.as_deref()
}

/// Returns the expression that created the snapshot.
pub fn expression(&self) -> Option<&str> {
self.expression.as_deref()
}

/// Returns the relative source path.
pub fn get_relative_source(&self, base: &Path) -> Option<PathBuf> {
self.source.as_ref().map(|source| {
base.join(source)
Expand Down

0 comments on commit 8593c9f

Please sign in to comment.