Method: O.require

Defined in:
lib/o.rb

.require(name) ⇒ O

load a configuration file, use $: and support ‘~/.gutenrc’

Examples:

Rc = O.require("~/.gutenrc")

Rc = O.require("/absolute/path/rc.rb")

Rc = O.require("guten/rc") #=> load 'APP/lib/guten/rc.rb'
# first try 'guten/rc.rb', then 'guten/rc'

Parameters:

  • name (String)

Returns:

  • (O)

Raises:



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/o.rb', line 96

def require(name)
  path = nil

  # ~/.gutenrc
  if name =~ /^~/
    file = File.expand_path(name)
    path = file if File.exists?(file)

  # /absolute/path/to/rc
  elsif File.absolute_path(name) == name
    path = name if File.exists?(name)

  # relative/rc
  else
    catch :break do
      $:.each { |p|
        ['.rb', ''].each { |ext|
          file = File.join(p, name+ext)
          if File.exists? file
            path = file
            throw :break
          end
        }
      }
    end
  end

  raise LoadError, "can't find file -- #{name}" unless path

  O.eval File.read(path)
end