Class: WindClutter::Util::FileHandler
- Inherits:
-
Object
- Object
- WindClutter::Util::FileHandler
- Defined in:
- lib/windclutter/util/file_handler.rb
Overview
Generator helper
Class Method Summary collapse
- .create_project(value) ⇒ Object
- .init_config ⇒ Object
- .list_projects ⇒ Object
- .overwrite(file, content) ⇒ Object
- .read(file) ⇒ Object
- .scan_one(path) ⇒ Object
- .scanners(suffixes) ⇒ Object
- .uninstall ⇒ Object
Class Method Details
.create_project(value) ⇒ Object
37 38 39 |
# File 'lib/windclutter/util/file_handler.rb', line 37 def self.create_project(value) FileUtils.mkdir_p("/tmp/windclutter/projects/#{value}") end |
.init_config ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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.('../../template', File.dirname(__FILE__)) puts 'First setup of windclutter...'.green 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_projects ⇒ Object
41 42 43 44 45 |
# File 'lib/windclutter/util/file_handler.rb', line 41 def self.list_projects Dir['/tmp/windclutter/projects/*'].map do |t| t.split('/tmp/windclutter/projects/')[1] end end |
.overwrite(file, content) ⇒ Object
55 56 57 |
# File 'lib/windclutter/util/file_handler.rb', line 55 def self.overwrite(file, content) File.open(file, 'w') { |t| t.puts content } end |
.read(file) ⇒ Object
59 60 61 |
# File 'lib/windclutter/util/file_handler.rb', line 59 def self.read(file) File.open(file).read end |
.scan_one(path) ⇒ Object
51 52 53 |
# File 'lib/windclutter/util/file_handler.rb', line 51 def self.scan_one(path) File.(path, Dir.pwd) end |
.scanners(suffixes) ⇒ Object
47 48 49 |
# File 'lib/windclutter/util/file_handler.rb', line 47 def self.scanners(suffixes) Dir[*suffixes.map { |s| "#{Dir.pwd}/**/*#{s}" }] end |
.uninstall ⇒ Object
31 32 33 34 35 |
# File 'lib/windclutter/util/file_handler.rb', line 31 def self.uninstall Dir['/tmp/windclutter'].each do |t| FileUtils.rm_rf(t) end end |