Module: Configuration::ClassMethods

Defined in:
lib/configuration.rb

Instance Method Summary collapse

Instance Method Details

#for(name, options = nil, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/configuration.rb', line 21

def for name, options = nil, &block
  name = name.to_s
  options = options.to_hash if options.is_a?( Configuration )

  if Table.has_key?(name)
    if options or block
      configuration = Table[name]
      Table[name] = DSL.evaluate(configuration, options || {}, &block)
    else
      Table[name]
    end
  else
    if options or block
      Table[name] = new name, options || {}, &block
    else
      load name
    end
  end
end

#load(name) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/configuration.rb', line 51

def load name
  name = name.to_s
  name = name + '.rb' unless name[%r/\.rb$/]
  key = name.sub %r/\.rb$/, ''
  load_path = $LOAD_PATH.dup
  begin
    $LOAD_PATH.replace(path + load_path)
    ::Kernel.load name
  ensure
    $LOAD_PATH.replace load_path
  end
  Table[key]
end

#path(*value) ⇒ Object



41
42
43
44
# File 'lib/configuration.rb', line 41

def path *value
  return self.path = value.first unless value.empty?
  Path
end

#path=(value) ⇒ Object



46
47
48
49
# File 'lib/configuration.rb', line 46

def path= value
  Path.clear
  Path.replace [value].compact.flatten.join(File::PATH_SEPARATOR).split(File::PATH_SEPARATOR)
end