Class: WindClutter::Util::FileHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/windclutter/util/file_handler.rb

Overview

Generator helper

Class Method Summary collapse

Class Method Details

.create_project(value) ⇒ Object



38
39
40
# File 'lib/windclutter/util/file_handler.rb', line 38

def self.create_project(value)
  FileUtils.mkdir_p("/tmp/windclutter/projects/#{value}")
end

.init_configObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/windclutter/util/file_handler.rb', line 11

def self.init_config
  FileUtils.mkdir_p('/tmp/windclutter')

  return puts 'Setup already performed!'.yellow if File.file?('/tmp/windclutter/config.yml')

  template = File.expand_path('../../template', File.dirname(__FILE__))

  puts 'Created the following files:'
  Dir["#{template}/*.yml"].each do |file|
    FileUtils.cp(file, '/tmp/windclutter')
  end

  Dir['/tmp/windclutter/*'].each do |file|
    puts "\t#{file}"
  end

  puts "\nSetup completed!".green
end

.list_projectsObject



42
43
44
45
46
# File 'lib/windclutter/util/file_handler.rb', line 42

def self.list_projects
  Dir['/tmp/windclutter/projects/*'].map do |t|
    t.split('/tmp/windclutter/projects/')[1]
  end
end

.overwrite(file, content) ⇒ Object



56
57
58
# File 'lib/windclutter/util/file_handler.rb', line 56

def self.overwrite(file, content)
  File.open(file, 'w') { |t| t.puts content }
end

.scan_one(path) ⇒ Object



52
53
54
# File 'lib/windclutter/util/file_handler.rb', line 52

def self.scan_one(path)
  File.expand_path(path, Dir.pwd)
end

.scanners(extension) ⇒ Object



48
49
50
# File 'lib/windclutter/util/file_handler.rb', line 48

def self.scanners(extension)
  Dir["#{Dir.pwd}/**/*#{extension}"]
end

.uninstallObject



30
31
32
33
34
35
36
# File 'lib/windclutter/util/file_handler.rb', line 30

def self.uninstall
  Dir['/tmp/windclutter'].each do |t|
    FileUtils.rm_rf(t)
  end

  puts 'Uninstall completed!'.green
end