Class: Temp::Config

Inherits:
Object
  • Object
show all
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.expand_path('~/.tempconf')
DEFAULT_TEMP_DIR =
File.expand_path('~/.temp')

Instance Attribute Summary collapse

Instance Method Summary collapse

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, template_options = {})
  @file = file
  @template_options = template_options

  if File.file? @file
    @vals = YAML::load_file(@file)
  else
    @vals = {
      :template_dir => DEFAULT_TEMP_DIR
    }
  end

  @template_dir = File.expand_path(@vals[:template_dir])
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



12
13
14
# File 'lib/temp/config.rb', line 12

def file
  @file
end

#template_dirObject (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_optionsObject

Returns the value of attribute template_options.



13
14
15
# File 'lib/temp/config.rb', line 13

def template_options
  @template_options
end

#valsObject (readonly)

Returns the value of attribute vals.



12
13
14
# File 'lib/temp/config.rb', line 12

def vals
  @vals
end