Sha256: d49000cd06fcea16e5fd4439655de67d96b46302f802dd8421c52e9d40ad0d3e

Contents?: true

Size: 1.12 KB

Versions: 38

Compression:

Stored size: 1.12 KB

Contents

use std::{collections::HashMap, rc::Rc};

/// The DEFINES variables from libruby.
#[derive(Debug, Clone)]
pub struct Defines {
    raw_environment: Rc<HashMap<String, String>>,
}

impl Defines {
    pub(crate) fn from_raw_environment(raw_environment: Rc<HashMap<String, String>>) -> Self {
        Self { raw_environment }
    }

    /// Determines the given key is true.
    pub fn is_value_true(&self, key: &str) -> bool {
        self.raw_environment
            .get(format!("DEFINES_{}", key).as_str())
            .map(|v| v == "1" || v == "true")
            .unwrap_or(false)
    }

    /// Fetches the raw value for the given key.
    pub fn get_raw_value(&self, key: &str) -> Option<&str> {
        self.raw_environment
            .get(format!("DEFINES_{}", key).as_str())
            .map(|v| v.as_str())
    }

    pub(crate) fn print_cargo_rustc_cfg(&self) {
        for (key, val) in self.raw_environment.iter() {
            if key.starts_with("DEFINES_") && val == "true" {
                let key = key.trim_start_matches("DEFINES_");
                rustc_cfg!("ruby_{}", key.to_lowercase());
            }
        }
    }
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-28.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-27.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-26.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-25.0.2 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-25.0.1 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-25.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-24.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-23.0.2 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-22.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-21.0.1 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-20.0.2 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-20.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-18.0.3 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-17.0.1 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-17.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-16.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-15.0.1 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-15.0.0 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs
wasmtime-14.0.4 ./ext/cargo-vendor/rb-sys-env-0.1.2/src/defines.rs