class
Movie::Config
- Movie::Config
- Reference
- Object
Overview
Config provides path-based access to configuration values.
Example: config = Movie::Config.builder .set("name", "my-system") .set("remoting.host", "127.0.0.1") .set("remoting.port", 9000) .build
config.get_string("name") # => "my-system" config.get_int("remoting.port") # => 9000 config.get_config("remoting") # => Config subsection
Defined in:
movie/config.crConstructors
-
.empty : Config
Creates an empty config.
-
.from_json(json_string : String) : Config
Parses a JSON string into a Config.
-
.from_yaml(yaml_string : String) : Config
Parses a YAML string into a Config.
-
.load(path : String, default : Config) : Config
Loads config from file with fallback for missing values.
-
.load(path : String) : Config
Loads config from file, detecting format by extension (.yml, .yaml, .json).
-
.load_json(path : String, default : Config) : Config
Loads a Config from a JSON file with fallback for missing values.
-
.load_json(path : String) : Config
Loads a Config from a JSON file.
-
.load_yaml(path : String, default : Config) : Config
Loads a Config from a YAML file with fallback for missing values.
-
.load_yaml(path : String) : Config
Loads a Config from a YAML file.
- .new(root : Hash(String, ConfigValue) = {} of String => ConfigValue)
Class Method Summary
-
.builder : ConfigBuilder
Creates a new ConfigBuilder for programmatic config construction.
Instance Method Summary
-
#[](path : String) : ConfigValue
Subscript access - returns raw ConfigValue
-
#[]?(path : String) : ConfigValue
Subscript access with nil for missing paths
-
#empty? : Bool
Returns true if config is empty.
-
#get_array(path : String) : Array(ConfigValue)
Returns the array value at the given path.
-
#get_bool(path : String, default : Bool) : Bool
Returns the boolean value at the given path, or default if not found.
-
#get_bool(path : String) : Bool
Returns the boolean value at the given path.
-
#get_config(path : String, default : Config) : Config
Returns a Config subsection at the given path, or empty Config if not found.
-
#get_config(path : String) : Config
Returns a Config subsection at the given path.
-
#get_duration(path : String, default : Time::Span) : Time::Span
Returns the duration value at the given path, or default if not found.
-
#get_duration(path : String) : Time::Span
Returns the duration value at the given path.
-
#get_float(path : String, default : Float64) : Float64
Returns the float value at the given path, or default if not found.
-
#get_float(path : String) : Float64
Returns the float value at the given path.
-
#get_int(path : String, default : Int32) : Int32
Returns the integer value at the given path, or default if not found.
-
#get_int(path : String) : Int32
Returns the integer value at the given path.
-
#get_int_array(path : String) : Array(Int32)
Returns an array of integers at the given path.
-
#get_long(path : String, default : Int64) : Int64
Returns the Int64 value at the given path, or default if not found.
-
#get_long(path : String) : Int64
Returns the Int64 value at the given path.
-
#get_string(path : String, default : String) : String
Returns the string value at the given path, or default if not found.
-
#get_string(path : String) : String
Returns the string value at the given path.
-
#get_string_array(path : String, default : Array(String)) : Array(String)
Returns an array of strings at the given path, or default if not found.
-
#get_string_array(path : String) : Array(String)
Returns an array of strings at the given path.
-
#get_value(path : String) : ConfigValue
Returns the raw value at the given path, or nil if not found.
-
#get_value!(path : String) : ConfigValue
Returns the raw value at the given path.
-
#has_path?(path : String) : Bool
Returns true if the given path exists in the config.
-
#keys : Array(String)
Returns all top-level keys.
-
#to_h : Hash(String, ConfigValue)
Returns the root hash (for serialization).
-
#with_env_overrides(prefix : String = "MOVIE") : Config
Returns a new Config with environment variable overrides applied.
-
#with_fallback(other : Config) : Config
Returns a new Config with values from other merged in.
-
#with_override(other : Config) : Config
Returns a new Config with values from other overriding self.
Constructor Detail
Parses a JSON string into a Config.
Example: config = Movie::Config.from_json(%({ "name": "my-system", "remoting": { "host": "127.0.0.1", "port": 9000 } }))
Parses a YAML string into a Config.
Example: config = Movie::Config.from_yaml(<<-YAML) name: my-system remoting: host: 127.0.0.1 port: 9000 YAML
Loads config from file with fallback for missing values. If file exists, loads it and uses default as fallback. If file doesn't exist, returns default.
Loads config from file, detecting format by extension (.yml, .yaml, .json).
Loads a Config from a JSON file with fallback for missing values. If file exists, loads it and uses default as fallback. If file doesn't exist, returns default.
Loads a Config from a YAML file with fallback for missing values. If file exists, loads it and uses default as fallback. If file doesn't exist, returns default.
Class Method Detail
Creates a new ConfigBuilder for programmatic config construction.
Instance Method Detail
Returns the boolean value at the given path, or default if not found.
Returns a Config subsection at the given path, or empty Config if not found.
Returns a Config subsection at the given path. Raises MissingConfigError if path doesn't exist. Raises WrongTypeConfigError if value is not a hash.
Returns the duration value at the given path, or default if not found.
Returns the duration value at the given path. Supports formats: "100ms", "5s", "2m", "1h", "1d" Also accepts numeric values as milliseconds.
Returns the float value at the given path, or default if not found.
Returns the integer value at the given path, or default if not found.
Returns the Int64 value at the given path, or default if not found.
Returns the string value at the given path, or default if not found.
Returns the string value at the given path. Raises MissingConfigError if path doesn't exist. Raises WrongTypeConfigError if value is not a string.
Returns an array of strings at the given path, or default if not found.
Returns an array of strings at the given path.
Returns the raw value at the given path, or nil if not found.
Returns the raw value at the given path. Raises MissingConfigError if path doesn't exist.
Returns a new Config with environment variable overrides applied. Environment variables are mapped from MOVIE_* pattern: MOVIE_NAME -> name MOVIE_REMOTING_PORT -> remoting.port MOVIE_CLUSTER_SEED_NODES -> cluster.seed_nodes
Values are auto-converted:
- "true"/"false" -> Bool
- Numeric strings -> Int64 or Float64
- Comma-separated -> Array(String)
- Other -> String
Example:
With MOVIE_REMOTING_PORT=9000 MOVIE_DEBUG=true
config = base_config.with_env_overrides config.get_int("remoting.port") # => 9000 config.get_bool("debug") # => true
Returns a new Config with values from other merged in. Values from other override values in self.
Returns a new Config with values from other overriding self.