Class: ConfigToolkit::RubyReader::Interpreter
- Inherits:
-
Object
- Object
- ConfigToolkit::RubyReader::Interpreter
- Defined in:
- lib/configtoolkit/rubyreader.rb
Overview
This is a helper class (not meant to be used externally). The Ruby code in Ruby configuration files is executed in the context of the instances of this class. It provides a config instance method that allows references to “config.param_name” in the configuration file to work. This method returns a ObjectProxy, which in turn re-implements method_missing so as to allow references to arbitrary parameters.
Defined Under Namespace
Classes: ObjectProxy, SimpleParam
Instance Method Summary collapse
-
#initialize ⇒ Interpreter
constructor
Description: This initializes the Interpreter with an empty configuration hash.
-
#interpret(code, file_path) ⇒ Object
Description: This method interprets (evals) code (which should have been sourced from a file with path file_path) and returns a Hash representing the configuration built by code.
Constructor Details
#initialize ⇒ Interpreter
Description:
This initializes the Interpreter with an empty configuration hash.
216 217 218 |
# File 'lib/configtoolkit/rubyreader.rb', line 216 def initialize @root_proxy = ObjectProxy.new("config") end |
Instance Method Details
#interpret(code, file_path) ⇒ Object
Description:
This method interprets (evals) code (which should have been sourced from a file with path file_path) and returns a Hash representing the configuration built by code
Parameters:
- code
-
The code containing the configuration to be interpreted (String)
- file_path
-
The path of the file containing the code (Pathname or nil)
Returns:
A Hash representing the configuration built by code
249 250 251 252 253 254 255 256 257 |
# File 'lib/configtoolkit/rubyreader.rb', line 249 def interpret(code, file_path) if(file_path == nil) instance_eval(code) else instance_eval(code, file_path.to_s()) end return @root_proxy.___config_hash___ end |