class

Movie::Config

Inherits Reference < Object

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

Constructors

empty

Creates an empty config.

Source
from_json(json_string : String) : Config

Parses a JSON string into a Config.

Example: config = Movie::Config.from_json(%({ "name": "my-system", "remoting": { "host": "127.0.0.1", "port": 9000 } }))

Source
from_yaml(yaml_string : String) : Config

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

Source
load(path : String, default : Config) : Config

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.

Source
load(path : String) : Config

Loads config from file, detecting format by extension (.yml, .yaml, .json).

Source
load_json(path : String, default : Config) : Config

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.

Source
load_json(path : String) : Config

Loads a Config from a JSON file.

Source
load_yaml(path : String, default : Config) : Config

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.

Source
load_yaml(path : String) : Config

Loads a Config from a YAML file.

Source
new(root : Hash(String, ConfigValue) = {} of String => ConfigValue)
Source

Class methods

builder

Creates a new ConfigBuilder for programmatic config construction.

Source

Instance methods

[](path : String) : ConfigValue

Subscript access - returns raw ConfigValue

Source
[]?(path : String) : ConfigValue

Subscript access with nil for missing paths

Source
empty?

Returns true if config is empty.

Source
get_array(path : String) : Array(ConfigValue)

Returns the array value at the given path.

Source
get_bool(path : String, default : Bool) : Bool

Returns the boolean value at the given path, or default if not found.

Source
get_bool(path : String) : Bool

Returns the boolean value at the given path.

Source
get_config(path : String, default : Config) : Config

Returns a Config subsection at the given path, or empty Config if not found.

Source
get_config(path : String) : Config

Returns a Config subsection at the given path. Raises MissingConfigError if path doesn't exist. Raises WrongTypeConfigError if value is not a hash.

Source
get_duration(path : String, default : Time::Span) : Time::Span

Returns the duration value at the given path, or default if not found.

Source
get_duration(path : String) : Time::Span

Returns the duration value at the given path. Supports formats: "100ms", "5s", "2m", "1h", "1d" Also accepts numeric values as milliseconds.

Source
get_float(path : String, default : Float64) : Float64

Returns the float value at the given path, or default if not found.

Source
get_float(path : String) : Float64

Returns the float value at the given path.

Source
get_int(path : String, default : Int32) : Int32

Returns the integer value at the given path, or default if not found.

Source
get_int(path : String) : Int32

Returns the integer value at the given path.

Source
get_int_array(path : String) : Array(Int32)

Returns an array of integers at the given path.

Source
get_long(path : String, default : Int64) : Int64

Returns the Int64 value at the given path, or default if not found.

Source
get_long(path : String) : Int64

Returns the Int64 value at the given path.

Source
get_string(path : String, default : String) : String

Returns the string value at the given path, or default if not found.

Source
get_string(path : String) : String

Returns the string value at the given path. Raises MissingConfigError if path doesn't exist. Raises WrongTypeConfigError if value is not a string.

Source
get_string_array(path : String, default : Array(String)) : Array(String)

Returns an array of strings at the given path, or default if not found.

Source
get_string_array(path : String) : Array(String)

Returns an array of strings at the given path.

Source
get_value(path : String) : ConfigValue

Returns the raw value at the given path, or nil if not found.

Source
get_value!(path : String) : ConfigValue

Returns the raw value at the given path. Raises MissingConfigError if path doesn't exist.

Source
has_path?(path : String) : Bool

Returns true if the given path exists in the config.

Source
keys

Returns all top-level keys.

Source
to_h

Returns the root hash (for serialization).

Source
with_env_overrides(prefix : String = "MOVIE") : Config

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

Source
with_fallback(other : Config) : Config

Returns a new Config with values from other merged in. Values from other override values in self.

Source
with_override(other : Config) : Config

Returns a new Config with values from other overriding self.

Source