refactor: replace get_* and set_* methods with direct field access

Co-authored-by: aider (openai/andrew/openrouter/anthropic/claude-sonnet-4) <aider@aider.chat>
This commit is contained in:
Andrew Phillips
2025-08-19 13:15:48 -03:00
parent 58ecbd63cf
commit 38cbf06579
7 changed files with 68 additions and 262 deletions

View File

@@ -100,21 +100,28 @@ pub trait MetaPlugin {
Ok(())
}
// Access to outputs mapping
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value>;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value>;
// Save metadata to database using central output handler
fn save_meta(&mut self, conn: &Connection, item_id: i64, internal_name: &str, value: String) -> Result<()> {
output_metadata(conn, item_id, internal_name, value, self.get_outputs())
output_metadata(conn, item_id, internal_name, value, self.outputs())
}
// Configure plugin with options and outputs
fn configure(&mut self, _options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs_mut().insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
// Get outputs mapping
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value>;
// Set outputs mapping
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>);
}
pub fn get_meta_plugin(meta_plugin_type: MetaPluginType) -> Box<dyn MetaPlugin> {

View File

@@ -90,23 +90,15 @@ impl MetaPlugin for BinaryMetaPlugin {
}
}
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
// Call default implementation for outputs
MetaPlugin::configure(self, options)
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}

View File

@@ -54,25 +54,12 @@ impl MetaPlugin for DigestSha256MetaPlugin {
self.meta_name.clone()
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -113,25 +100,12 @@ impl MetaPlugin for ReadTimeMetaPlugin {
self.meta_name.clone()
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -174,24 +148,11 @@ impl MetaPlugin for ReadRateMetaPlugin {
self.meta_name.clone()
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}

View File

@@ -130,31 +130,22 @@ impl MetaPlugin for MagicFileMetaPlugin {
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
if let Some(max_buffer_size) = options.get("max_buffer_size") {
if let Some(size) = max_buffer_size.as_u64() {
self.max_buffer_size = size as usize;
}
}
Ok(())
// Call default implementation for outputs
MetaPlugin::configure(self, options)
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}

View File

@@ -152,24 +152,11 @@ impl MetaPlugin for MetaPluginProgram {
}
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}

View File

@@ -55,25 +55,12 @@ impl MetaPlugin for CwdMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -119,25 +106,12 @@ impl MetaPlugin for UidMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -186,25 +160,12 @@ impl MetaPlugin for UserMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -250,25 +211,12 @@ impl MetaPlugin for GidMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -317,25 +265,12 @@ impl MetaPlugin for GroupMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -384,25 +319,12 @@ impl MetaPlugin for ShellMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -451,25 +373,12 @@ impl MetaPlugin for ShellPidMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -515,25 +424,12 @@ impl MetaPlugin for KeepPidMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -582,25 +478,12 @@ impl MetaPlugin for HostnameMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}
@@ -667,24 +550,11 @@ impl MetaPlugin for FullHostnameMetaPlugin {
Ok(())
}
fn configure(&mut self, options: &std::collections::HashMap<String, serde_yaml::Value>) -> Result<()> {
if let Some(outputs) = options.get("outputs") {
if let Some(outputs_map) = outputs.as_mapping() {
for (key, value) in outputs_map {
if let Some(key_str) = key.as_str() {
self.outputs.insert(key_str.to_string(), value.clone());
}
}
}
}
Ok(())
}
fn get_outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
fn outputs(&self) -> &std::collections::HashMap<String, serde_yaml::Value> {
&self.outputs
}
fn set_outputs(&mut self, outputs: std::collections::HashMap<String, serde_yaml::Value>) {
self.outputs = outputs;
fn outputs_mut(&mut self) -> &mut std::collections::HashMap<String, serde_yaml::Value> {
&mut self.outputs
}
}

View File

@@ -48,11 +48,9 @@ fn setup_compression_and_plugins(
let plugin_name = meta_plugin.meta_name();
if let Some(config) = meta_plugin_configs.iter().find(|c| c.name == plugin_name) {
// Set outputs first
let mut outputs = std::collections::HashMap::new();
for (key, value) in &config.outputs {
outputs.insert(key.clone(), serde_yaml::Value::String(value.clone()));
meta_plugin.outputs_mut().insert(key.clone(), serde_yaml::Value::String(value.clone()));
}
meta_plugin.set_outputs(outputs);
// Then configure with options
if let Err(e) = meta_plugin.configure(&config.options) {