Module: Meta::Filelib

Defined in:
lib/meta/filelib.rb

Class Method Summary collapse

Class Method Details

.create_directory(name) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/meta/filelib.rb', line 5

def self.create_directory(name)

  unless name.nil?

    if File.directory?(name)
      puts "directory already exists".yellow
    else
      FileUtils.mkdir_p(name)
      puts "directory #{name} created".green
    end

  end

end

.create_file(text, filename, ext, dest, overwrite = false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/meta/filelib.rb', line 20

def self.create_file( text, filename, ext, dest, overwrite=false )

  filename = File.basename( filename, File.extname(filename) ) + ext
  filename = dest + SLASH + filename

  reply   = false
  write   = false

  if File.exists?(filename)

    reply = agree("file #{filename} exists, overwrite?".red) {
      |q| q.default = "n" } unless overwrite

  else
    write = true
  end

  if overwrite or reply or write
 
    f = File.open( filename, "w" )
    f.write(text)
    f.close

    if overwrite or reply
      puts "file #{filename} overwritten".green
    else
      puts "file #{filename} created".green
    end

  end

end

.get_contentsObject



57
58
59
# File 'lib/meta/filelib.rb', line 57

def self.get_contents
  return Dir.glob( Meta::MARKDOWN, File::FNM_CASEFOLD )
end

.get_templates(pattern) ⇒ Object



53
54
55
# File 'lib/meta/filelib.rb', line 53

def self.get_templates(pattern)
  return Dir.glob( pattern, File::FNM_CASEFOLD )
end