Class: Config
- Inherits:
-
Object
- Object
- Config
- Defined in:
- lib/calimero/config/config.rb
Overview
Configuration class that holds a Keypair and is extensible for future for other fields
Instance Attribute Summary collapse
-
#keypair ⇒ Object
readonly
Returns the value of attribute keypair.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Allow dynamic access to raw config data.
-
#initialize(file_path) ⇒ Config
constructor
Initialize with a TOML file path.
-
#method_missing(method_name, *args, &block) ⇒ Object
Extend config with additional fields in the future.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(file_path) ⇒ Config
Initialize with a TOML file path
13 14 15 16 17 18 |
# File 'lib/calimero/config/config.rb', line 13 def initialize(file_path) @config_data = load_toml(file_path) keypair_value = @config_data.dig('identity', 'keypair') raise ConfigError, "'keypair' not found in [identity] section" unless keypair_value @keypair = Ed25519Keypair.new(keypair_value) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Extend config with additional fields in the future
26 27 28 29 30 31 32 |
# File 'lib/calimero/config/config.rb', line 26 def method_missing(method_name, *args, &block) if @config_data.key?(method_name.to_s) @config_data[method_name.to_s] else super end end |
Instance Attribute Details
#keypair ⇒ Object (readonly)
Returns the value of attribute keypair.
10 11 12 |
# File 'lib/calimero/config/config.rb', line 10 def keypair @keypair end |
Instance Method Details
#[](key) ⇒ Object
Allow dynamic access to raw config data
21 22 23 |
# File 'lib/calimero/config/config.rb', line 21 def [](key) @config_data[key] end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
34 35 36 |
# File 'lib/calimero/config/config.rb', line 34 def respond_to_missing?(method_name, include_private = false) @config_data.key?(method_name.to_s) || super end |