Top Level Namespace

Defined Under Namespace

Modules: Rubot Classes: Auth, Help, Join, Msg, Object, Part, Quit, Reload, String, UpTime

Instance Method Summary collapse

Instance Method Details

#generate(template, name) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/template.rb', line 39

def generate(template, name)
  FileUtils.mkdir(template) unless Dir.exist?(template)
  filename = File.join(template, "#{name.underscore}.rb")
  puts "file '#{filename}' already exists" and return if File.exist?(filename)
  
  template_file = File.join(File.dirname(__FILE__), "generators", "#{template}.template")
  source = IO.read(template_file).gsub(/--NAME--/, name.camelize)
  File.open(filename, "w") {|file| file.write(source)}
end

#generate_command(name) ⇒ Object



23
24
25
# File 'lib/template.rb', line 23

def generate_command(name)
  generate("commands", name)
end

#generate_exiter(name) ⇒ Object



35
36
37
# File 'lib/template.rb', line 35

def generate_exiter(name)
  generate("exiters", name)
end

#generate_listener(name) ⇒ Object



27
28
29
# File 'lib/template.rb', line 27

def generate_listener(name)
  generate("listeners", name)
end

#generate_runner(name) ⇒ Object



31
32
33
# File 'lib/template.rb', line 31

def generate_runner(name)
  generate("runners", name)
end

#init(name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/template.rb', line 4

def init(name)
  if Dir.exist? name
    puts "directory '#{name}' already exists"
    return
  end
  
  template_dir = File.join(File.dirname(__FILE__), "template")
  
  FileUtils.cp_r(template_dir, name)
  
  dir_structure = %w{resources commands listeners runners}
  
  # for some reason gem doesn't include empty folders during the install.
  # this is to make sure these directories exist
  dir_structure.each do |dir|
    FileUtils.mkdir File.join(name, dir) unless File.exist? File.join(name, dir)
  end
end