class Rutema::Configuration
The object we pass around after we load the configuration from file
All relevant methods are in Rutema::ConfigurationDirectives
Attributes
filename[R]
Public Class Methods
new(config_file)
click to toggle source
# File lib/rutema/core/configuration.rb, line 165 def initialize config_file @filename=config_file init load_configuration(@filename) end
Public Instance Methods
configure() { |self| ... }
click to toggle source
# File lib/rutema/core/configuration.rb, line 171 def configure if block_given? yield self end end
import(filename)
click to toggle source
Loads the configuration from a file
Use this to chain configuration files together
Example¶ ↑
Say you have on configuration file “first.rutema” that contains all the generic directives and several others that change only one or two things.
You can import the first.rutema file in the other configurations with
import("first.rutema")
# File lib/rutema/core/configuration.rb, line 184 def import filename fnm = File.expand_path(filename) if File.exist?(fnm) load_configuration(fnm) else raise ConfigurationException, "Import error: Can't find #{fnm}" end end
Private Instance Methods
load_configuration(filename)
click to toggle source
# File lib/rutema/core/configuration.rb, line 193 def load_configuration filename begin cfg_txt=File.read(filename) cwd=File.expand_path(File.dirname(filename)) #WORKAROUND for ruby 2.3.1 fname=File.basename(filename) #evaluate in the working directory to enable relative paths in configuration Dir.chdir(cwd){eval(cfg_txt,binding(),fname,__LINE__)} rescue ConfigurationException #pass it on, do not wrap again raise rescue SyntaxError #Just wrap the exception so we can differentiate raise ConfigurationException.new,"Syntax error in the configuration file '#{filename}':\n#{$!.message}" rescue NoMethodError raise ConfigurationException.new,"Encountered an unknown directive in configuration file '#{filename}':\n#{$!.message}" rescue #Just wrap the exception so we can differentiate raise ConfigurationException.new,"#{$!.message}" end end