Class: Temp::Config
- Inherits:
-
Object
- Object
- Temp::Config
- Defined in:
- lib/temp/config.rb
Overview
A Config object loads the Temp configuration file and provides access to its values for other parts of Temp.
Constant Summary collapse
- DEFAULT_CONF_FILE =
File.('~/.tempconf')
- DEFAULT_TEMP_DIR =
File.('~/.temp')
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#template_dir ⇒ Object
readonly
Returns the value of attribute template_dir.
-
#template_options ⇒ Object
Returns the value of attribute template_options.
-
#vals ⇒ Object
readonly
Returns the value of attribute vals.
Instance Method Summary collapse
-
#initialize(file = DEFAULT_CONF_FILE, template_options = {}) ⇒ Config
constructor
Loads a configuration file and sets the configuration variables to the values in the file.
Constructor Details
#initialize(file = DEFAULT_CONF_FILE, template_options = {}) ⇒ Config
Loads a configuration file and sets the configuration variables to the values in the file. If not given a filename, loads the default configuration file. If the configuration file doesn’t exist, uses default configuration values. Also accepts template options to make it easier to pass to tempfiles.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/temp/config.rb', line 20 def initialize(file = DEFAULT_CONF_FILE, = {}) @file = file @template_options = if File.file? @file @vals = YAML::load_file(@file) else @vals = { :template_dir => DEFAULT_TEMP_DIR } end @template_dir = File.(@vals[:template_dir]) end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
12 13 14 |
# File 'lib/temp/config.rb', line 12 def file @file end |
#template_dir ⇒ Object (readonly)
Returns the value of attribute template_dir.
12 13 14 |
# File 'lib/temp/config.rb', line 12 def template_dir @template_dir end |
#template_options ⇒ Object
Returns the value of attribute template_options.
13 14 15 |
# File 'lib/temp/config.rb', line 13 def @template_options end |
#vals ⇒ Object (readonly)
Returns the value of attribute vals.
12 13 14 |
# File 'lib/temp/config.rb', line 12 def vals @vals end |