Class: Boot::Lib::Core::Config
- Inherits:
-
Object
- Object
- Boot::Lib::Core::Config
- Defined in:
- lib/Boot/Lib/Core/Config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
config array.
-
#templates_path ⇒ Object
readonly
The include paths.
Instance Method Summary collapse
-
#initialize(config) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(config) ⇒ Config
Returns a new instance of Config.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/Boot/Lib/Core/Config.rb', line 13 def initialize(config) @config = config # Append the lib/templates dir to templates_path in config if (@config.key?('templates_path')) if (@config['templates_path'].is_a?(String)) @config['templates_path'] = [@config['templates_path']] end if (!@config['templates_path'].is_a?(Array)) msg = "templates_path in config must be either a string or array" fail InvalidConfigException.new msg end i = 0 while (i < @config['templates_path'].length) # Expand all paths in templates_path # Starting in the user directory user_dir = File.('~/') path = @config['templates_path'][i] @config['templates_path'][i] = File.(path, user_dir) i+=1 end else @config['templates_path'] = [] end # Add lib/templates # This will be the last place to look for a template @config['templates_path'].push(Boot.dir + "/templates/templates") @templates_path = @config['templates_path'] # If templates_path is not defined if @templates_path.nil? msg = '' msg << "Invalid config file: templates_path not defined\n" msg << "Please set this to the directory(s) where your\n" msg << "templates are located\n" fail InvalidConfigException.new msg end # If templates_path is defined, but invalid path if !@templates_path.is_a?(Array) && !File.directory?(@templates_path) msg = '' msg << "Invalid config file: '#{@templates_path}' is not a directory\n" msg << "Please set this to the directory(s) where your " msg << "templates are located\n" fail InvalidConfigException.new msg end # If templates_path is an array if @templates_path.is_a?(Array) notDirs = [] # Add each path that is invalid to notDirs @templates_path.each do |path| notDirs.push(path) unless File.directory? path end # If any element in notDirs, invalid config if notDirs.length > 0 msg = '' msg << "Invalid config file:\n" msg << 'the path(s): ' + notDirs.join(', ') + "\n" msg << "Are not directories\n" fail InvalidConfigException.new msg end end end |
Instance Attribute Details
#config ⇒ Object (readonly)
config array
8 9 10 |
# File 'lib/Boot/Lib/Core/Config.rb', line 8 def config @config end |
#templates_path ⇒ Object (readonly)
The include paths
11 12 13 |
# File 'lib/Boot/Lib/Core/Config.rb', line 11 def templates_path @templates_path end |