Module: Pathsconfig::Base::InstanceMethods

Defined in:
lib/pathsconfig/base.rb

Instance Method Summary collapse

Instance Method Details

#path_array(path_name) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pathsconfig/base.rb', line 10

def path_array(path_name)
  raise Pathsconfig::ConfigError, "Pathsconfig has not been configured." unless Pathsconfig.config
  raise Pathsconfig::ModelError, "class '#{self.class.name}' does not respond to the 'path_config' method." unless self.class.respond_to?(:path_config)
  path_value = Pathsconfig.config[self.class.path_config.to_sym][path_name.to_sym]
  if path_value.kind_of?(Hash)
    raise Pathsconfig::ModelError, "multiple path types are configured and this model does not respond to the 'path_type' method." unless self.respond_to?(:path_type)
    raise Pathsconfig::ModelError, "an '#{self.path_type}' type of the '#{path_name}' path has not been configured" if path_value[self.path_type.to_sym].nil?
    path_value[self.path_type.to_sym].collect{ |exp| eval(exp) }.flatten
  elsif path_value.kind_of?(Array)
    path_value.collect{ |exp| eval(exp) }.flatten
  elsif path_value.nil? || path_value.empty?
    raise Pathsconfig::ModelError, "'#{path_name}' is not configured for #{self.class.name}"
  else
    raise Pathsconfig::ModelError, "'#{path_name}' is incorrectly configured for #{self.class.name}"
  end
end

#path_string(path_name, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pathsconfig/base.rb', line 27

def path_string(path_name, options={})
  options ||= {}
  options[:type] ||= :system
  options[:root] ||= Pathsconfig.root

  case options[:type].to_sym
  when :system
    File.join((options[:root] + self.path_array(path_name)).compact)
  else
    ""
  end
end