Movie::Config
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
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 methods
Instance methods
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.