Top Level Namespace

Defined Under Namespace

Modules: Rink Classes: Object

Instance Method Summary collapse

Instance Method Details



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'bin/rink', line 30

def banner
  puts "Usage:"
  puts "  rink [My::Console] [path/to/file]"
  puts
  puts "By default, Rink::Console will be used. If path is omitted, the"
  puts "current directory will be used."
  puts
  puts "Rink will check ./[file] and ./lib/[file] for the console to"
  puts "load, where [file] is the underscored class name. For example,"
  puts "App::Console would be found in either ./app/console.rb or "
  puts "./lib/app/console.rb"
  puts
  exit
end

#find_class(name, path) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'bin/rink', line 4

def find_class(name, path)
  if const = eval(name)
    return const
  end rescue nil
  
  paths = [path, File.join(path, "lib")]
  filename = name.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
    gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
  
  filename += ".rb" unless filename[/\.rb$/]

  paths.each do |dir|
    file = File.expand_path(File.join(dir, filename))
    if File.exist?(file)
      load file
      if const = eval(name)
        puts "Loaded constant #{const} from #{file}"
        puts
        return const
      end rescue nil
    end
  end
  
  raise "Console could not be found: #{name}\n  (searching for '#{filename}' in #{paths.inspect})"
end